The Artima Developer Community
Sponsored Link

Java Community News
Advanced Facelets

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Frank Sommers

Posts: 2642
Nickname: fsommers
Registered: Jan, 2002

Advanced Facelets Posted: May 11, 2006 9:30 AM
Reply to this message Reply
Summary
Facelets aim to solve a mismatch between JSP and JSF by defining a templating language built with the JSF component life cycle in mind. Rick Hightower's article on advanced Facelets development shows how to internationalize with Facelets, define and use custom logic tags, and how to do metaprogramming with Facelets.
Advertisement

The main problem in working with JSPs and JSFs emanates from the different execution models of these technologies. JSPs define an expression language that result in a servlet's doPost() and doGet() methods. By contrast, JSF defines a component model, with component life cycles independent of any servlet life cycle.

While the latest JSP and JSF specifications aim to bridge this gap with a unified expression language, Facelets defines a template language outside the JSP and JSF standards with an eye toward the needs of JSF components, but one that's still familiar to developers accustomed to JSTL, JSF, or JSP.

Rick Hightower covers Facelets programming in a two-part IBM DeveloperWorks series. The first installment introduces the basic Facelets development model with an example application, while the second part features advanced Facelets techniques.

The advanced part of the article shows an example of internationalizing a components with Facelets:

[This] field composition component uses the field name as its default label if the label is not passed, as shown here:

<c:if test="${empty label}">
     <c:set var="label" value="${fieldName}" />
</c:if>

Instead of loading the fieldName as its default label, you want the field composition component to look up the fieldName in the resource bundle associated with Faces. For this, you create a tag library that defines tags and EL functions. First, you create an EL function that looks up a fieldName in the resource bundle. If it can't find the label in the resource bundle, it tries to generate a fieldName based on the camel case of the given fieldName.

<c:if test="${empty label}">
   <c:set var="label" value="${arc:getFieldLabel(fieldName,namespace)}" />
</c:if>

The article then shows how to create the arc:getfieldLabel() EL function.

Another interesting Facelets example in the article shows a custom IsTypeHandler() tag handler that decides if a component gets added to the component tree based on a component's type. This tag handler results in isBoolean, isText, and isDate() tags used in this manner:

<!--  If the value binding is a boolean, display a
           selectBooleanCheckbox field. -->
<arc:isBoolean id="vb">
   <h:selectBooleanCheckbox  id="#{fieldName}" value="#{entity[fieldName]}" required="${required}" />
</arc:isBoolean>

What were your challenges using JSP and JSF together? And what's your experience using Facelets?

Topic: Advanced Facelets Previous Topic   Next Topic Topic: JDBC with Spring

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use