これは私の複合コンポーネント名ファイルで、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 名には、セッション Scope 内のタブがあります。
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 は、setter、getter を含むセッション スコープの単なる通常の Bean です。
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 を使用しましたrender 属性ですが、例外に不明な id ':tabTags:tabTags が含まれています - コンポーネント dynamicTabs のコンテキストでそれを見つけることができません。f:ajax は @form 属性値のみを受け入れます。誰か何か考えがありますか?アイデアですか?ありがとうございます。この質問にはすでに数日かかりました。