这是我的复合组件名称文件是tab.xhtml
<composite:interface>
<composite:attribute name="totalTabs"/>
<composite:attribute name="tabNameList" required="true"/>
</composite:interface>
<composite:implementation>
<div id="#{cc.id}" columns="#{cc.attrs.totalTabs}"styleClass="adjustTabsTableColumnMargin">
<ui:repeat id="repeat" var="tabItem" value="#{cc.attrs.tabNameList}" varStatus="status">
<h:commandLink id="dynamicTabs" tabindex = "#{status.index + 1}" title="#{tabItem.title}" value="#{tabItem.name}" styleClass = "#{tabItem.isSelected?'tabSelected':'tabPane'}" >
<f:setPropertyActionListener name="tabs.tabIndex" value="#{status.index + 1}"/>
<f:ajax execute="#{@this}" listener="#{tabs.handleTabChange(tabItem, cc.attrs.tabNameList)}" render="@form"/>
</h:commandLink>
</ui:repeat>
</div>
</composite:implementation>
在支持bean名称中是选项卡,在会话范围内。
public void handleTabChange(TabBean tabItem, List<TabBean> tabBeanList){
for(TabBean tab: tabBeanList){
if(tabItem.tabName.equal(tab.tabName){
tab.setIsSelected(true);
}else{
tab.setIsSelected(false);
}
}
并且tabBean只是会话范围内的常规bean,包含setter,getter,
TabBean(String tabname, String title, String id, boolean select){
this.tabname = tabname;
this.title = title;
this.id = id;
this.select = select;
}
public void setIsSelected(boolean value){this.selected = value;}
public boolean getIsSelected(){ return this.selected;}
@PostContruct
public List<TabBean> getTabPaneList(){
List<TabBean> tabList = new ArrayList<TabBean>();
TabBean tab = new TabBean("name1", "title1", "tab1", true);
tabList.add(tab);
tab = new TabBean("name2", "title2", "tab2", false);
tabList.add(tab);
return tabList;
}
在我的主display.xhtml文件标签中是:
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:tp="http://ui.pax"
template="/WEB-INF/layouts/standard_layout.xhtml"
xmlns:uitags="http://java.sun.com/jsf/composite/uitags">
<h:form id="formId" prePendid="false">
<uitag:tab id ="tabTags" tabNameList="#{tab.getTabNameList}" />
</h:form>
</ui:composition>
当用户选择新标签时,我希望标签更改颜色,f:不重新渲染ajax 用户选择新选项卡时的一组选项卡,保留默认选项卡是第一个选项卡我使用了id:tabTags:tabTags in render属性但是有一个包含未知id的异常':tabTags:tabTags - 无法找到它组件dynamicTabs的上下文,f:ajax只接受@form属性值,任何人都有任何想法,Baulse你有什么想法吗?谢谢,这个问题已经花了几天时间,我现在处于热门席位。