我正在研究使用延迟加载的 JSF 选项卡示例:
<h:form prependId="false">
<h:panelGroup id="tabs" layout="block">
<ul>
<c:forEach items="#{DatacenterProfileController.tabs}" var="tab">
<li><a href="##{tab.tabid}" onclick="$('#button_#{tab.tabid}').click()">#{tab.tabid}</a></li>
<h:commandButton id="button_#{tab.tabid}" value="TabClick" action="#{DatacenterProfileController.switchPages(tab.tabid)}" style="display:none">
<f:ajax render="tabs"></f:ajax>
</h:commandButton>
</c:forEach>
</ul>
<c:forEach items="#{DatacenterProfileController.tabs}" var="tab">
<h:panelGroup id="#{tab.tabid}" layout="block" rendered="#{tab.tabid eq DatacenterProfileController.selectedTab}">
<ui:include src="#{tab.tabfilename}"></ui:include>
</h:panelGroup>
</c:forEach>
</h:panelGroup>
</h:form>
List<TabObject> tabs = new ArrayList<>();
@PostConstruct
public void init() {
tabs.add(new TabObject("DCProfileTabZones.xhtml", "Zones"));
tabs.add(new TabObject("DCProfileTabHVAC.xhtml", "HVAC"));
tabs.add(new TabObject("DCProfileTabISPs.xhtml", "ISPs"));
}
String selectedTab = "Zones";
public String getSelectedTab() {
return selectedTab;
}
public void setSelectedTab(String selectedTab) {
this.selectedTab = selectedTab;
}
public String switchPages(String selTab) {
selectedTab = selTab;
return selectedTab;
}
public List<TabObject> gettabs() {
return tabs;
}
public void setTabs(List<TabObject> tabs) {
this.tabs = tabs;
}
public class TabObject {
String tabfilename;
String tabid;
public String gettabfilename() {
return tabfilename;
}
public void settabfilename(String tabfilename) {
this.tabfilename = tabfilename;
}
public String getTabid() {
return tabid;
}
public void settabid(String tabid) {
this.tabid = tabid;
}
public TabObject(String tabfilename, String tabid) {
super();
this.tabfilename = tabfilename;
this.tabid = tabid;
}
}
我注意到一个非常奇怪的错误。我有三个选项卡:区域、HVAC、ISP。如果我在单击选项卡时具有相同的 jsf 页面,则会打开具有相同名称的 JSF 页面。你能帮我修复这个错误吗?