I want to create Primefaces tabs from Java List. I tested this code:
<p:tabView value="#{DatacenterProfileController.data}" var="listItem">
<p:tab title="#{listItem.name}">
<ui:insert>
<ui:include src="#{listItem.page}" />
</ui:insert>
</p:tab>
</p:tabView>
private List<PagesObj> dataList = new ArrayList<>();
public class PagesObj {
private String name;
private String page;
public PagesObj(String name, String page) {
this.name = name;
this.page = page;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPage() {
return page;
}
public void setPage(String page) {
this.page = page;
}
}
@PostConstruct
public void datagenerate(){
dataList.add(new PagesObj("General", "DCProfileTabGeneral.xhtml"));
dataList.add(new PagesObj("Zones", "DCProfileTabZones.xhtml"));
dataList.add(new PagesObj("Generators", "DCProfileTabGenerators.xhtml"));
dataList.add(new PagesObj("HVAC", "DCProfileTabHVACs.xhtml"));
}
public List<PagesObj> getdata() {
return dataList;
}
But for some reason the body of the tabs is not loaded properly - I get empty body tab maybe because the file is not found. Can you help me to solve the problem, please?
I found that this is an issue, using include with tabView Issue 4051
So this is working example:
<p:tabView id="tabW">
<c:forEach items="#{DatacenterProfileController.data}" var="listItem">
<p:tab title="#{listItem.name}">
<h:panelGrid columns="2" cellpadding="10">
<ui:include src="#{listItem.page}.xhtml" />
</h:panelGrid>
</p:tab>
</c:forEach>
</p:tabView>
Took from this primefaces forum
Can not test it right now, but i think that ui:insert is not needed. Therefore your code should be
<p:tabView value="#{DatacenterProfileController.data}" var="listItem">
<p:tab title="#{listItem.name}">
<ui:include src="#{listItem.page}" />
</p:tab>
</p:tabView>
Also ensure that this page is in the same directory as the included pages
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With