DZone
Java Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Java Zone > JSF: Beware the Difference Between Build-Time and Render-Time Tags in Facelets

JSF: Beware the Difference Between Build-Time and Render-Time Tags in Facelets

Jakub Holý user avatar by
Jakub Holý
·
Oct. 31, 11 · Java Zone · Interview
Like (0)
Save
Tweet
15.65K Views

Join the DZone community and get the full member experience.

Join For Free

This is to remind me that I should never ever forget the cruical difference between build-time-only tags (i.e. having tag handlers only) and render-time tags that have corresponding components. The problem is that their lifespan is different and thus mixing them can easily lead to nasty surprises. Build time tags are used to modify the building of a component tree and have no effect during its rendering, where only the components participate.

A typical mistake is the nesting of ui:include (build-time) inside ui:repeat (render-time) using the var that ui:repeat declares:
<ui:repeat value="#{bean.books}" var="book">
   <ui:include src="#{book.type}-template.xhtml" />
</ui:repeat>

This won’t work as intended because the var is only made available at the render time while ui:include is already evaluated at that point as it was invoked at the build time.

This is why combining JSTL and JSF isn’t recommended in general. The complication with Facelets is that there is no clear distinct mark such as the namespace prefix that would distinguish build-time and render-time tags. In adition to JSTL also f.ex. f:actionListener, f:facet, ui:include, and any custom tag file are build-time while  e.g. f:selectItems, ui:repeat,h:inputText, and any custom UIComponent are render time. An addition to that it seems that f:converter and f:validator are yet another special case [3] (though more like build-time tags).

So make sure that you know which tags are build-time and which are render-time and when it is meaningful to mix them and when you should absolutely avoid it.

References (highly recommended to read through):

  1. Andrew: Build time vs. render time  (2008) – mainly about JSP but the last section relates it to Facelets, which have the same problem with its tag handlers as JSP with its (non-JSF) tags
  2. BalusC: Why @ViewScoped fails in tag handlers (2011, JSF 2.0) – the author lists render-time alternatives for build-time tags where available
  3. Roger Keays: c:forEach vs ui:repeat in Facelets  (2007)

 

From http://theholyjava.wordpress.com/2011/10/28/jsf-beware-the-difference-between-build-time-and-render-time-tags-in-facelets/

Facelets

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Building a Login Screen With React and Bootstrap
  • A First Look at CSS When and Else Statements
  • ETL, ELT, and Reverse ETL
  • Fintech and AI: Ways Artificial Intelligence Is Used in Finance

Comments

Java Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo