Tot
Tot

Reputation: 207

IF statement does not work inside Primefaces DataTable

I want to show a row only if I have data for it. The code which i have is:

<p:dataTable id="comments" var="comment"
        value="#{agencyBean.getCommentByAgency(agencyBean.tAgency)}"
        paginator="true" >

        <p:column>  
            #{comment.author.name}  
        </p:column>

        <p:column>
            <c:if test="${not empty comment.positiveComment}">
                <p:row>
                    <p:column>
                        <p:graphicImage library="images" name="positive.png" />
                    </p:column>
                    <p:column>  #{comment.positiveComment}  </p:column>
                </p:row>
                <br />
            </c:if>
        </p:column>
    </p:dataTable>

But nevertheless I have data, the row is not shown. How can i implement this logic? Thanks!

Upvotes: 0

Views: 8732

Answers (1)

Omar
Omar

Reputation: 1440

Try to place the condition expression in the <p:row>'s tag itself, by using its rendered attribute :

<p:column>
    <p:row rendered="#{not empty comment.positiveComment}">
        <p:column>
            <p:graphicImage library="images" name="positive.png" />
        </p:column>
        <p:column>  #{comment.positiveComment}  </p:column>
    </p:row>
    <br />
</p:column>

Upvotes: 3

Related Questions