Templating with JSF 2.0 Facelets

A new article on otn/java, “Templating with JSF 2.0 Facelets,” by Deepak Vohra, offers a concise explanation of how to use Facelets, which in JavaServer Faces (JSF) 2.0, has replaced JavaServer Pages (JSP) as the default view declaration language (VDL). With Facelets, developers no longer need to configure a view handler as they once did in JSF 1.2.

From the article itself:

“Facelets is a templating framework similar to Tiles. The advantage of Facelets over Tiles is that JSF UIComponents are pre-integrated with Facelets, and Facelets does not require a Facelets configuration file, unlike Tiles, which requires a Tiles configuration file.

JSF Validators and Converters may be added to Facelets. Facelets provides a complete expression language (EL) and JavaServer Pages Standard Tag Library (JSTL) support. Templating, re-use, and ease of development are some of the advantages of using Facelets in a Web application.

In this article, we develop a Facelets Web application in Oracle Enterprise Pack for Eclipse 11g and deploy the application to Oracle WebLogic Server 11g. In the Facelets application, an input text UIComponent will be added to an input Facelets page. With JSF navigation, the input Facelets page is navigated to another Facelets page, which displays the JSF data table generated from the SQL query specified in the input Facelets page. We will use Oracle Database 11g Express Edition for the data source. Templating is demonstrated by including graphics for the header and the footer in the input and the output; the graphics have to be specified only once in the template.”

Read the complete article here.

Comments:

Is there any tutorial for templating with JSF?

Posted by Mag on August 19, 2011 at 12:37 AM PDT #

Hi Mag,

You might find this page helpful:

http://download.oracle.com/javaee/6/tutorial/doc/giepx.html

Jan Heiss

Posted by guest on August 19, 2011 at 05:37 AM PDT #

Judging by that article, developing a JSF application is still cumbersome. And using WebLogic when a plain web server will do? Big no-no.

Posted by alex on August 19, 2011 at 10:47 AM PDT #

Alex

Thanks for the feedback.

"Judging by that article, developing a JSF application is still cumbersome. And using WebLogic when a plain web server will do? Big no-no."

JSF is not at all cumbersome. Rather to the contrary. Especially JSF 2.0. Not all the new JSF 2.0 features were discussed in the article as the article only demonstrates Facelets. But, the Facelets templating may be further simplified by:
1. Using implicit navigation instead of faces-config.xml.
2. Using the new @ManagedBean annotation for configuring a managed bean.

Some of the web servers do not include a JSF 2.0 implementation packaged with the server as WebLogic does a shared library for JSF 2.0. The jsf 2.0 JAR files would be required to be downloaded separately with some of the web servers, which is cumbersome.

Deepak

Posted by guest on August 19, 2011 at 01:02 PM PDT #

For an introduction(not too detailed) to all the new features in JSF 2.0 please refer

New Features in JavaServer Faces 2.0
http://java.sys-con.com/
http://java.sys-con.com/node/1952954

Posted by Deepak on August 22, 2011 at 11:49 AM PDT #

The article is well done, but does not take advantage of JSF 2 navigation, and uses a web.xml, and faces-config.xml which are not required for the most part.

The configuration with WL is a pain, but the article is focused on it along with Eclipse. They both need coverage, but another commenter points out all of the configuration, etc. as complex. I agree based on the platform and tools.

Perhaps you should try NetBeans instead. It is easier to use and develop JSF based applications. GlassFish, the RI for EE 6 just works too.

Posted by John Yeary on August 23, 2011 at 03:35 PM PDT #

John

Thanks for the feedback.

JSF 1.2 navigation and configuration has been used as covering all the new JSF 2.0 features in an article is not feasible; discussing implicit navigation, conditional navigation and preemptive navigation would require some additional discussion.

But as suggested earlier the faces-config.xml may be made any empty file by replacing with the @ManagedBean annotation and implicit navigation in the managed bean:

@ManagedBean(name = "catalog")
public class Catalog {

....
....
public String commandButton1_action() {
// Add event code here...

try {

....
....

dataTable1.setValue(dataModel);

} catch (SQLException e) {
System.out.println(e.getMessage());
return "error";

} catch (ClassNotFoundException e) {
System.out.println(e.getMessage());
return "error";
} finally {

}
return "output";
}
}

Deepak

Posted by Deepak on August 26, 2011 at 01:43 PM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Insider News from the Java Team at Oracle!

duke
javeone logo
Links


Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
2
5
6
7
12
13
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today