JSF Mini Book – Tips, concepts and good practices

Upgrading from JSF 1.2 to 2.0

Before upgrading the framework to a newest version we must think about the “cost x benefits”. Companies do not like to stop the production of a new product or wait more for new functionalities just to change a framework that was already working.

To request a framework upgrading like this, the developer must be ready with a clear vision of the advantages of this upgrade and the needed effort. When the companies see the required effort it chooses to keep the old and outdated framework.

To upgrade from JSF 1.2 to JSF 2.0 a developer need to know that it can be done with a minimal effort and keep the JSP without the use of Facelets or upgrade the JSF to use with Facelets with bigger effort or using JSP and XHTML at the same time. To execute the upgrade some common actions should be taken in both cases:

  • To remove the JSF 1.2 libraries.
  • Add the JSF 2.0 libraries to the “WebContent/WEB-INF/lib” folder. Your container may raise a JSF libraries conflict “ClassLoader” exception.  Check in Table 01 below some solutions.
  • Edit the header/root of the “faces-config.xhml” file to the JSF 2.0 version, check the Code 03 bellow.
  • Edit the header/root of the “web.xml” to work with (no lesser than) the servlet 2.5 version, as is displayed in the Code 04. JSF 2.0 does not work naturally with servlet version smaller than 2.5.

To change the JSP pages to XHTML pages:

  • Change the page structure – the ideal is to use the h:head and the h:body tags instead of using head and body only. Some frameworks, like Primefaces, require those tags.
  • Remove the Scriplets – Scriplets are not allowed in XHTML pages.
  • Include – the pages should change the way of including other pages. Instead of using <jsp:includepage=”page.jsp”/>” a developer should use “<ui:include src=”newPage.xhtml” />”.
  • The components should change to adapt to the new version. Click here to see guide to show how to edit the old JSF 1.2 components to JSF 2.0.

It is possible an approach where the application will have JSP and XHTML working at the same time. With this approach it will be possible to upgrade the pages one by one. To set up the application to work with this approach, Code 05 should be added to the web.xml file. The access to the JSP should be done by the URL “mysite.com/faces/old.jsp”; to access the migrated pages: “mysite.com/faces/new.xhtml”.

Container Upgrading JSF Action
JBoss 4x to the 6x (version 6 inclusive) Just add the configuration in the Code 01
JBoss 6 and 7 The container already has its JSF libs. There is no need to add the libs in the “/WebContent/WEB-INF/lib” folder of the generated EAR/WAR.
Glassfish 2.x to Glassfish 3.x version Add the configurations found in the Code 02 to the “sun-web.xml” file.
Websphere 5.x to 8.x version Define the WAR/EAR as “PARENT_LAST” in the WAS control panel. With this configuration the application library will be used instead the JSF server implementation.
WebLogic The version 10.3.3.0 already supports JSF 2.0

Table 01–how to use JSF 2.0 with servers

Code 1

<context-param>
    <param-name>org.jboss.jbossfaces.WAR_BUNDLES_JSF_IMPL</param-name>
    <param-value>true</param-value>
</context-param>

Code 2

<class-loader delegate="false" />
<property name="useBundledJsf" value="true" />

Code 3

<faces-config xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd" version="2.0">

Code 4

<web-app id="WebApp_ID" version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

Code 5

<context-param>
    <param-name>javax.faces.FACELETS_VIEW_MAPPINGS</param-name>
    <param-value>*.xhtml</param-value>
</context-param>

<context-param>
    <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
    <param-value>.jsp</param-value>
</context-param>

18 thoughts on “JSF Mini Book – Tips, concepts and good practices

  1. Really cool material! I agree with Tim. If this could be distributed in pdf format, you will become a little more famous. :) Thanks, good job!

  2. I’m not able to see this library applied in my program.
    Output is: Real Madrid, Champion!!! (No image and style)

    Please let me know what I’m missing.

  3. I was trying to learn Spring MVC for last 2 months, Every time i try to start, i get stuck somewhere. 2 Months passed, and i did not learn anything. I purchased two books for spring. Finally i quit Java web programming. One day I thought to give a try to JSF. and found some tutorials online, worked on them and I loved it. Your tutorials are going to help me a lot.
    Thank you so much.
    I would like to tell people here, don’t go near spring, It’s a piece of crap.

    • Arslan,

      Thanks for the feedback.

      My next post will be a full web application with Spring MVC.

      Maybe this application will help you understanding better the Spring, it is a good tool! =D

      See you later.

  4. With your code lines

    and

    eclipse was giving error that:

    Multiple annotations found at this line:
    – Invalid location of text (“) in tag ().
    – Invalid location of text (=”) in tag ().
    – Element type “h:outputStylesheetlibrary” must be followed by either attribute specifications, “>”
    or “/>”.

    So I’ve corrected it by changing lines to

    But I think as you mentioned in case of versions of resources, it will automatically picks up latest version. but the code I’m using will not control the version. It looks like hard-coded.

    What you say about it?

    Moreover, You wrote:
    “To use a mapped library by the ResourceHandler let us create a folder named “index.xhtml” inside the folder “/WebContent”.”

    I think you have not created a folder name “index.xhtml” but you have created a file named “index.xhtml”. If I’m right then you need to correct it. :)

    • Hello Arslan, how are you?

      Unfortunately the xml are not displayed here. =/

      Could you send me an email with the code and the texts that you wrote?

      Thanks for your support and passing by.

      My email is contato (at] uaihebert (d0T) com

      Thanks

Leave a Comment