Wednesday, December 22, 2010

Create dynamic Tab using Primefaces 1.1 and JSP

Development Environment:  JSP, Myfaces1.2.5, JBoss5, Primefaces1.1
Goal: Generate tabs dynamically.
Solution: use c:forEach

 <c:forEach var="bean" items="#{YourBackendBean.yourList}" >
        <p:tab title="#{bean.name}">
         <h:outputText value="#{bean.value}" />
        </p:tab>
 </c:forEach>

While the following things have to be done to make this work:
  1. use JSP2.1, instead of JSP2.0
  2. use JSTL1.2. instead of JSTL1.0
#1 can be done by changing the web.xml to use Servlet2.5, which will enable JSP2.1
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
     xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

#2 can be done by putting jstl-1.2.jar in the WEB-INF/lib

No comments:

Post a Comment