在更改下拉值时更改 class 禁用选项卡

Change class of disabled tab on change of dropdown value

我有 1 个下拉菜单,根据下拉菜单的值选项卡将启用或禁用。默认情况下,我对所有选项卡使用 getTabContainerCssClass(),它将所有选项卡显示为启用视图,但我想更改选项卡 css class,因为它看起来像是在更改下拉值后被禁用。

DropDownChoice ProductDropDown = new DropDownChoice("ProductList", new PropertyModel(this, "SupplierProduct"),ProductList, new choiceRenderer("name","id"));
add(supplierProductDropDown);

supplierProductDropDown.add(new AjaxFormComponentUpdatingIndicatingBehavior("onchange"){
            @Override
            protected void onUpdate(AjaxRequestTarget target) {
                 /* do some code for changing dropdown */
            }
      });

tabs = new ArrayList<AbstractTab>();

/* provide some tab details */

tab = new AjaxTabbedPanel("tabs", tabs){

        private static final long serialVersionUID = 1L;

        @Override
        protected String getTabContainerCssClass() {
            return "producttab-row";
        }
        @Override
        protected WebMarkupContainer newLink(String linkId, final int index) {

            return new Link(linkId)
            {
                    private static final long serialVersionUID = 1L;

                    public void onClick() {
                            setSelectedTab(index);
                    }

                    @Override
                    public boolean isEnabled() {
                        if(index == 1 && /*drop down condition that will be disable the tab*/){
                            /*I want to change css of this tab*/
                            return false;
                        }
                        else{
                            return true;
                        }
                    }
            }
       }
}

关于这个的任何想法......

更新:更新代码后

 @Override
                    protected void onComponentTag(final ComponentTag tag) {
                    // TODO Auto-generated method stub
                        super.onComponentTag(tag);
                        if(/*Dropdown condition*/){

                             tag.append("class", "disabletab", " ");
                         }
}

但这并没有奏效。请帮助

解决方案:我在 AjaxTabbedPanel.see 下面的代码

中覆盖了 onComponentTag
tabs = new ArrayList<AbstractTab>();

/* provide some tab details */

tab = new AjaxTabbedPanel("tabs", tabs){

    private static final long serialVersionUID = 1L;

    @Override
    protected String getTabContainerCssClass() {
        return "producttab-row";
    }
@Override
            protected void onComponentTag(final ComponentTag tag)
            {
            super.onComponentTag(tag);

            String cssClass = tag.getAttribute("class");
            if (cssClass == null)
            {
                cssClass = " ";
            }
            /*check condition and change css classname*/
            tag.put("class", cssClass.trim());
        }
}

您应该覆盖 Link#onComponentTag(ComponentTag) 方法并设置 CSS class 为:tag.append("class", "dynamicValueDependingOnDropDownsModel", " ").