Question

I have searched and tried but this time I'm really stuck.

I am trying to build a simple datatable (primefaces) where the cell content can be of different types. There is a holder class for each cell content that can hold different entities and I want to use < c:choose> to check and display the right entity in the entity specific way.

The code looks like:

<p:dataTable emptyMessage="" value="#{date.getThreadContent(column.propertyID)}" var="content">

                    <p:column>
                        #{content.type}

                        <c:choose>
                            <c:when test="#{content.type == 'activity'}">
                                #{content.activity.name}
                            </c:when>   
                            <c:when test="#{content.type == 'todo'}">
                                #{content.activity.name}
                            </c:when>
                            <c:otherwise>
                                Neither activity or todo
                            </c:otherwise>
                        </c:choose>
                    </p:column>

                </p:dataTable>

The EL evaluation doesn't work regardless if I try a boolean or String values in the bean (I'm using String value in the code above). So each time the content is not empty, the output first displays the correct content type from #{content.type} but then together with 'Neither activity or todo'.

I can also say that this data table itself represents a cell content in a parent data table (list of entities per date) that is not visible in this code as I try to isolate the problem.

Could it be that this type of expression cannot be done in a ? Any help is appreciated.

Was it helpful?

Solution

Use JSF rendered tags to do your conditional display logic, it removes it from the DOM completely and makes validations easier.

Refer: http://docs.oracle.com/javaee/6/tutorial/doc/bnaik.html for EL expressions Also a good explanation is provided by BalusC here: JSTL c:if doesn't work inside a JSF h:dataTable

<p:dataTable emptyMessage="" value="#{date.getThreadContent(column.propertyID)}" var="content">
   <p:column>
         #{content.type}
          <h:outputText value="#{content.activity.name}" rendered="#{content.type == 'activity' or content.type == 'todo'}" />

          <h:outputText value="Neither activity or todo" rendered="#{content.type != 'activity' and content.type != 'todo'}" />   
   </p:column>

</p:dataTable>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top