Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

is jstl c:if tag better than rendered attribute of JSF???  RSS feed

 
Akash Singla
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please comment..

Thanks
Akash
 
Tim Holloway
Bartender
Posts: 18662
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No.

I've written more JSF apps than I can count over the last couple of years and not used JSTL in any of them. Partly because in earlier JSF releases JSTL didn't play well with JSF, partly because the JSF equivalents are usually more compact, and partly because JSTL makes it too easy to start sliding controller logic into the view and thus muddy the maintainability of the webapp.

JSTL doesn't track the JSF document tree the way that JSF components do, so there's always potential for confusion. This is especially true when you conditionally include/exclude/iterate items.
 
Cedric Bosch
Ranch Hand
Posts: 99
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm kinda bumping this old topic because it's one of the first I get if I do a google search rendered vs c:if.

Render attribute is executed at render time and c:if at build time. The confusion that Tim was talking about is about the view build time and the render phase. So as long as one understands that there shouldn't be any problem.

The gist I get from a detailed answer from balusC here :http://stackoverflow.com/questions/3342984/jstl-in-jsf2-facelets-makes-sense, is that when the view is gonna be static it is better to use c:if tag. The reason is that since the render tag happens at render time, the UIComponents are gonna be added to the render tree, which is not needed in a static page.

For example


Would be better than



As long as the page isn't supposed to update the connection of the user through ajax.
 
Tim Holloway
Bartender
Posts: 18662
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm afraid I'm going to have to be dogmatic here. While I have seen JSF examaples on Oracle's website where they use JSTL, in actual practice, it's more trouble than it's worth.

I have absolutely zero JSTL in my webapps and don't miss it - JSF has native constructs that do the job as well or better.

A more salient point, however, is that JSTL is designed as a tag library for JSPs. JSPs are translated to Java Servlets, then the Servlets are compiled. A "c:if" tag translates directly into a Java "if" statement.

But JSF doesn't use JSPs. The JSF View Template language is not compiled into code, it's digested into a data tree. Data shouldn't be logic. If you have a need for an "if" tag that cannot be served by a native JSF construct, the probability is very high that you are muddling the Separation of Concerns between Model, View, and Controller and that frequently translates to "maintenance headache".

Another reason to steer clear of JSTL is that JSF may become even more detached from code-like behavior in its View handling in future releases, which means that JSTL-based stuff could break.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!