Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does p:panelGrid not work with ui:repeat?

If I use as below, I get no error, no output. Why does p:panelGrid not work with ui:repeat?

Note : I don't want to use c:forEach because of the I already face a lot of JSF issue.

<p:panelGrid>
    <ui:repeat value="#{MyBean.dataList}" var="data">
        <p:row>
            <p:column>
                <h:outputText value="#{data.name}"/>
            </p:column>
            <p:column>
                <h:outputText value="#{data.description}"/>
            </p:column>
        </p:row>
    </ui:repeat>
</p:panelGrid>

MyBean.java

public List<Data> getDataList(){
    List<Data> result = new ArrayList<Data>();
    result.add(new Data("Name 1", "Description 1"));
    result.add(new Data("Name 2", "Description 2"));
    result.add(new Data("Name 3", "Description 3"));
    result.add(new Data("Name 4", "Description 4"));
    return result;
}   

Expected output with primefaces

enter image description here

like image 336
Zaw Than oo Avatar asked Oct 19 '12 10:10

Zaw Than oo


1 Answers

ui:repeat will not work because it does not actually add components to the component tree.

ui:repeat only works during the render phase, and rerenders its child components multiple times with different state.

Some components, such as panelgrid, but also datatable, expect to have certain children in the component tree in order to work correctly. Since ui:repeat does not add these, this approach does not work.

I'm sorry, but the normal solution for this is to use c:foreach, which does add children to the tree.

See https://rogerkeays.com/jsf-c-foreach-vs-ui-repeat

like image 72
Joeri Hendrickx Avatar answered Oct 15 '22 07:10

Joeri Hendrickx