Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

jsf 2 - ui:repeat JSF 2.0 cannot render iterate p:row primefaces

I got a problem here, my system config was Mojarra 2.1.7, Primefaces 3.2 and using Glassfish 3.1+.

before this, i got my code well rendered using this codes:

<p:tabView>
    <p:tab title="Offices Access" >
         <h:outputText value="Access | Offices Name | Offices Code | Parent Offices" style="font-weight: bold;"/>

         <ui:repeat value="#{userBean.officeses}" var="office">
              <h:panelGrid columns="2">
                   <p:selectBooleanCheckbox id="access#{office.officesID}" style="width: 50px;"/>
                   <h:outputLabel for="access#{office.officesID}" value="#{office.officesName} | #{office.officesCode} | #{office.parentOffices}"/>
               </h:panelGrid>
         </ui:repeat>
     </p:tab>
</p:tabView>  

and i find this is generate rather ugly interfaces, so i ran over p:panelGrid from primefaces.
after i write some code and from my expectation it would work, but it DONT :(
this code render the header perfectly, but right after the ui:repeat code, it wouldnt render the p:row and the p:column inside it.

here is the code :

<p:tabView>
    <p:tab title="Offices Access" >
        <p:panelGrid styleClass="centerContent">
             <f:facet name="header">
                 <p:row>
                     <p:column style="font-weight: bold;">Access</p:column>
                     <p:column style="font-weight: bold;">Offices Name</p:column>
                     <p:column style="font-weight: bold;">Offices Code</p:column>
                     <p:column style="font-weight: bold;">Above Level Offices</p:column>
                 </p:row>
            </f:facet>

            <ui:repeat value="#{userBean.officeses}" var="office">
                <p:row id="rowforOffice#{office.officesID}">
                    <p:column><p:selectBooleanCheckbox id="access#{office.officesID}"/></p:column>
                    <p:column><h:outputText value="#{office.officesName}"/></p:column>
                    <p:column><h:outputText value="#{office.officesCode}"/></p:column>
                    <p:column><h:outputText value="#{office.parentOffices}"/></p:column>
                </p:row>
            </ui:repeat>
       </p:panelGrid>
    </p:tab>
</p:tabView>  

am i miss something..?
or it is was a bug..? because i ran over google looking for this kind of code and i found nothing.
Regards,
bLueZ

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

As to the concrete problem, the <ui:repeat> is a view render time tag. Thus, it's physically present in the JSF component tree and generates its HTML output as many times as it needs to iterate over the value.

However, the <p:panelGrid> expects physically multiple <p:row> or <p:column> children, not a single <ui:repeat> with therein a single <p:row>. In other words, they needs to be prepared during the view build time instead of the view render time.

The JSTL <c:forEach> is a view build time tag. It will generate physically multiple <p:row> components into the JSF component tree and hence the <p:panelGrid> will find solely <p:row> children.

<p:panelGrid styleClass="centerContent">
    <c:forEach items="#{userBean.officeses}" var="office">
        <p:row id="rowforOffice#{office.officesID}">
            <p:column><p:selectBooleanCheckbox id="access#{office.officesID}"/></p:column>
            <p:column><h:outputText value="#{office.officesName}"/></p:column>
            <p:column><h:outputText value="#{office.officesCode}"/></p:column>
            <p:column><h:outputText value="#{office.parentOffices}"/></p:column>
        </p:row>
    </c:forEach>
</p:panelGrid>

Note: this breaks view scoped beans in Mojarra versions older than 2.1.18. If you can't upgrade, then consider a <p:dataTable> instead, as you already found out yourself.

See also:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...