1
votes

Having this xhtml code:

    <?xml version='1.0' encoding='UTF-8' ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
      xmlns:p="http://primefaces.org/ui">
    <h:head>
        <title>Simple JSF</title>
    </h:head>
    <h:body>
        <h:form>
           <ui:repeat value="#{cart.items}" var="item">
                        <h:panelGrid columns="2" cellpadding="10">
                             <h:outputText value="#{item}" />
                        </h:panelGrid>
            </ui:repeat> 
          </h:form>
     </h:body>
</html>

And the bean:

import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
@ManagedBean(name = "cart")
@SessionScoped
public class CartBean {
 private List<String> items;
 public CartBean() {
    items = new ArrayList<>();
    items.add("shirt");
    items.add("skirt");
    items.add("trouser");
  }
 public List<String> getItems() {
    return items;
  }
}

Shows the three corresponding items in the outputText: "shirt", "skirt" and "trouser" But, changing the body of xhtml like shows:

    <h:body>
        <h:form>
          <p:tabView >
                <ui:repeat value="#{cart.items}" var="item">
                    <p:tab title="#{item}">
                        <h:panelGrid columns="2" cellpadding="10">
                             <h:outputText value="#{item}" />
                        </h:panelGrid>
                    </p:tab>
                </ui:repeat>
          </p:tabView>
         </h:form>
     </h:body>

Showing a tabView whit only one tab (instead of three) and without text in the tab. I dont undernstand why loosing data?

2

2 Answers

1
votes

You don't use an ui:repeat inside the tabview to generate tabs. Tabview has its own iteration feature:

<p:tabView value="#{cart.items}" var="item">
    <p:tab title="#{item}">
        <h:outputText value="#{item}"/>
        ... etc.
    </p:tab>
</p:tabView>
1
votes

Solved using tabView owner iterator instead of ui:repeat and adding this to web.xml file:

<context-param>
      <param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
      <param-value>true</param-value>   
</context-param>