Dynamic number of tabs in tabView

UI Components for JSF
Post Reply
arungupta
Posts: 9
Joined: 11 Aug 2010, 21:37

21 Dec 2010, 09:20

If index.xhtml has the fragment as ...

<p:tabView>
<p:tab title="#javaee6">
<ez:columnChart
trends="#{chartBean.javaee6Trends}"
title="#javaee6"/>
</p:tab>
. . .
</p:tabView>

then all the tabs show up correctly. The following code is used In order to make the number of tabs dynamic:

<p:tabView>
<ui:repeat value="#{chartBean.indexBean}" var="index">
<p:tab title="#{index.title}">
<ez:columnChart
trends="#{index.trends}"
title="#{index.title}"/>
</p:tab>
</ui:repeat>
</p:tabView>

However no tabs are shown in this case. I've ensured that chartBean.indexBean return title/trends correctly. Any idea what is missing ?

Thanks,
Arun

Franke
Posts: 49
Joined: 12 Oct 2010, 08:41

21 Dec 2010, 09:41

ui:repeat does not work with p:tab of any sort. It is its own component, and tabView looks for tabs, not a repeat. The only possible way I have found of having dynamic content such as this is to use the old jstl forEach, but that breaks viewscoped beans. If you use request or session scope, it could be a solution for you.
Using PF 3.0 with default JSF implementation of JBoss 6

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

21 Dec 2010, 12:25

I think we can enable ui:repeat, if we introduce a renderer for p:tab. I've been thinking about this for some time to enable ui:repeat in components like accordion and tabview. Something to think about for 2.3.

arungupta
Posts: 9
Joined: 11 Aug 2010, 21:37

21 Dec 2010, 17:58

I think adding ui:repeat would be really useful as that would be more JSF-centric way of repeating.

OK, here is the updated code fragment ...

<p:tabView>
<c:forEach items="#{chartBean.indexBean}" var="index">
<p:tab title="#{index.title}">
<p:columnChart
value="#{index.trends}"
var="t"
xfield="#{t.tweeter}"
titleX="#{index.title}"
titleY="Tweets"
live="true"
height="400px"
width="800px"
refreshInterval="180000"> <!-- 3 x 60 x 1000 = 3 minutes -->
<p:chartSeries label="" value=" #{t.tweets}" />
</p:columnChart>
</p:tab>
</c:forEach>

IndexBean has two fields:

String title;
String trends;

How can #{index.trends} be sent as an EL expression instead of plain String ? Otherwise the following exception is thrown (rightly so):

java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Collection
at org.primefaces.component.chart.CartesianChartRenderer.encodeData(CartesianChartRenderer.java:95)
at org.primefaces.component.chart.CartesianChartRenderer.encodeScript(CartesianChartRenderer.java:66)
at org.primefaces.component.chart.CartesianChartRenderer.encodeEnd(CartesianChartRenderer.java:44)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:878)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1620)

arungupta
Posts: 9
Joined: 11 Aug 2010, 21:37

21 Dec 2010, 19:46

Never mind, changed my String to Collection and it is working now :-)

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

25 Jul 2011, 17:35


Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 34 guests