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
<context-param> <param-name>org.jboss.jbossfaces.WAR_BUNDLES_JSF_IMPL</param-name> <param-value>true</param-value> </context-param>
<class-loader delegate="false" /> <property name="useBundledJsf" value="true" />
<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">
<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">
<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>