views:

289

answers:

3

Hi all,

I would like to output a bit of XHTML code conditionally.

For that purpose, the JSTL tags seem to work fine:

<c:if test="${lpc.verbose}">
...
</c:if>

However, I'm not sure if this is a best practice? Is there another way to achieve my goal?

Thx J.

+3  A: 

use

<h:panelGroup rendered="#{lpc.verbose}">
  ...
</h:panelGroup>
Bozho
Thx, great answer. More in general: Do JSTL tags still make sense or should we consider them as deprecated since JSF 2.0?
Jan
In most cases, yes. But sometimes it is appropriate to use them
Bozho
A: 

In general, from the previous answer by Bozho, is there some reason to use JSP in JSF2.0 at all? Including JSP then requires processing by JSP engine which in turn means additional overhead to processing of the request. IMO, if possible, avoid use of JSP.

Note: I am not an anti-JSP warrior :)

Martin
I don't associate JSTL one-to-one with JSP anymore. If I understand correctly, JSTL is now part of the 'Unified EL'. However, it strikes me that in JSF books like Ed Burn's one, the Unified EL is hardly mentioned.
Jan
You are perfectly right JSP != JSTL. If JSF does not have appropriate tag for desired functionality then usage of JSTL is definitely valid and does not require any processing by JSP engine.
Martin
With facelets and jsf2.0 you have almost All you need so you Can stay with JSF alone.
Thorbjørn Ravn Andersen
+2  A: 

JSTL tags are executed during view build time while JSF tags are executed during view render time.

You can visualize it as follows: Whenever a view tree get created for the first time, all JSTL tags are executed and the result is a view with only JSF tags. Whenever a view tree get rendered, all JSF tags get executed and the result is HTML. So: JSF+JSTL doesn't run in sync as you'd expect from the coding. JSTL runs from top to bottom first, hands the result to JSF and then it's JSF's turn to run from top to bottm again. This may lead to unexpected results in JSF iterating components like UIData.

In a nut: Use JSTL to control flow of JSF result. Use JSF to control flow of HTML result.


That said, you can also use <f:verbatim> if all you want to render conditionally is just HTML without any JSF component. It has less overhead than a <h:panelGroup>.

BalusC