Board index JavaServer Faces General Data table and <c:if>

Data table and <c:if>

Components, Ajax Framework, Utilities and More.

Post 14 Oct 2010, 16:00

Posts: 15
Hi.

I'm having problems using <c:if> inside p:dataTable, using PrimeFaces 1.1.
By using the car-example as base, I have this data table declaration:

<p:dataTable var="car" value="#{carBean.cars}">
   <p:column>
      <f:facet name="header">
         <h:outputText value="Model" />
      </f:facet>
      <h:outputText value="#{car.model}" />
   </p:column>
   <p:column>
      <f:facet name="header">
         <h:outputText value="Year" />
      </f:facet>
      <h:outputText value="#{car.year}" />
   </p:column>
   <p:column>
      <f:facet name="header">
         <h:outputText value="Manufacturer" />
      </f:facet>
      <h:outputText value="#{car.manufacturer}" />
   </p:column>
   <p:column>
      <f:facet name="header">
         <h:outputText value="Color" />
      </f:facet>
      <h:outputText value="#{car.color}" />
   </p:column>
   <p:column>
      <f:facet name="header">
         <h:outputText value="Test" />
      </f:facet>
      <c:if test="#{car.}">
         <h:outputText value="True" />
      </c:if>
   </p:column>
   <p:column>
      <f:facet name="header">
         <h:outputText value="Test" />
      </f:facet>
      <h:outputText value="#{car.testBoolean}" />   Displays "true".
      <c:if test="#{car.testBoolean}">
         <h:outputText value="Test is true" />   Never displayed.
      </c:if>
   </p:column>
</p:dataTable>


In the car-class, I have:
public boolean getTestBoolean() {
   return true;
}


I.e. the <c:if>-test always fails. If I do the same test outside of the data table, it works fine.

Post 15 Oct 2010, 00:20

Posts: 365
<p:column> has a rendered attribute - use this instead of the jstl
lib. I recently tried using jstl and it simply didn't work at all, I was
highly surprised. I'm using PF 2.0.2 and Mojarra 2.0.3 and only have
the PrimeFaces 2.1 user guide, but give it a go. If you're using
NetBeans you should get help on the taglib attributes available using
CTRL+Space, but you already know that.

Regards,
Brendan.

p.s. although it's not immediately obvious the rendered attribute can
completely replace the functionality of c:if. Us programmers tend to not
instinctively recognise this! just a thought...

p.p.s

BTW my gripe against the problems I experienced with jstl were nothing
to do with PrimeFaces per se, more as a general issue with JSF 2 and
who knows what. I'm too busy to narrow it down, but rendered= works
for me, this is the way to go. You just need a slight mental re-adjustment
in order to achieve the required outcome. Good luck and come back with
any feedback.

Post 15 Oct 2010, 11:10

Posts: 4
I have the same problem.

When trying to check if a value is not null, it always proceed from the selection (tried both c:if and c:when) even if the value is null.

Is this a known bug?

Post 15 Oct 2010, 12:18

Posts: 15042
Location: Cybertron

Jstl is an old technology, in JSF world things can be done with rendered option;

<h:outputText value="#{car.somethingBoolean ? 'Yes' : 'No'} />


or

<h:outputText value="True" rendered="#{car.somethingBoolean}"/>
PrimeFaces Lead

Post 15 Oct 2010, 15:45

Posts: 4
Works good using the rendering-option.

Though I still think it's odd that it didn't work with the c:if-statement.

Thanks a lot!


Return to General