Data table and <c:if>

UI Components for JSF
Post Reply
Robelind
Posts: 15
Joined: 01 Dec 2009, 09:11

14 Oct 2010, 16:00

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:

Code: Select all

<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:

Code: Select all

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.

healeyb
Posts: 365
Joined: 07 Apr 2010, 16:05

15 Oct 2010, 00:20

<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.

fredrikj
Posts: 4
Joined: 15 Oct 2010, 11:04

15 Oct 2010, 11:10

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?

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

15 Oct 2010, 12:18

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

Code: Select all

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

Code: Select all

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

fredrikj
Posts: 4
Joined: 15 Oct 2010, 11:04

15 Oct 2010, 15:45

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!

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 21 guests