Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<h1>Painfulness</h1> <p>Painfulness of upgrading JSF 1.2 to 2.0 depends on the view technology which you are currently using and which you want to use.</p> <ul> <li>JSP 2.x to JSP 2.x = Almost no effort.</li> <li>Facelets 1.x to Facelets 2.0 = Little effort.</li> <li>JSP 2.x to Facelets 2.0 = Lot of effort. Double this if you also have custom components.</li> </ul> <hr> <h2>Basic changes</h2> <p>Regardless of the view technology switch, <em>at least</em> the following steps should be done:</p> <ul> <li>Remove JSF 1.2 JAR's from <code>/WEB-INF/lib</code> (if any).</li> <li>Drop JSF 2.0 JAR's in <code>/WEB-INF/lib</code> (if JSF 1.2 was servletcontainer-supplied, you might want to change the classloading policy to load webapp libraries first before servletcontainer libraries, see also <a href="https://stackoverflow.com/questions/5815623/jsf-2-issues-in-application-servers">JSF2 classloading issues in application servers</a>).</li> <li><p>Update root declaration of <code>faces-config.xml</code> to comply JSF 2.0 spec.</p> <pre class="lang-xml prettyprint-override"><code>&lt;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"&gt; </code></pre></li> <li><p>Ensure that root declaration of <code>web.xml</code> already complies <em>at least</em> Servlet 2.5. JSF 2.0 won't work on 2.4 or lower (<a href="https://stackoverflow.com/questions/5998447/running-jsf-2-0-on-servlet-2-4-container">although it's hackable</a>).</p> <pre class="lang-xml prettyprint-override"><code>&lt;web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 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" id="YourWebappID" version="2.5"&gt; </code></pre></li> </ul> <hr> <h2>JSP 2.x to JSP 2.x</h2> <p>If you're using <strong>JSP 2.x</strong> and want to <strong>keep</strong> using it, then you basically don't need to change anything else. </p> <h3>Gradually upgrading</h3> <p>If you're already using a suffix <code>url-pattern</code> for the <code>FacesServlet</code>, like <code>*.jsf</code>, then it's good to know that the <code>FacesServlet</code> will first scan for <code>*.xhtml</code> file and if it is not present, then scan for <code>*.jsp</code> file. This provides you room to gradually convert from JSP to Facelets behind the scenes without changing the URL's. </p> <p>But if you're using a prefix <code>url-pattern</code>, like <code>/faces/*</code> and you want to gradually upgrade from JSP to Facelets, then you really have to change it to <code>*.jsf</code> and possibly also all links in the existing JSP pages.</p> <p>You only need to keep in mind that the new JSF 2.0 provided implicit navigation doesn't scan for the presence of the file, it will go to <code>outcome.xhtml</code> anyway. So if you want to come from or go to <code>*.jsp</code>, then you still need to include it in the viewid the JSF 1.x way.</p> <hr> <h2>Facelets 1.x to Facelets 2.0</h2> <p>If you're using <strong>Facelets 1.x</strong> as view technology and want to use the JSF 2.0 supplied <strong>Facelets 2.0</strong>, then you need to do the following additional steps:</p> <ul> <li>Remove Facelets 1.x JAR from <code>/WEB-INF/lib</code>.</li> <li>Remove Facelets 1.x <code>FaceletViewHandler</code> from <code>faces-config.xml</code>.</li> <li>Any custom <code>FaceletViewHandler</code> implementation needs to be updated to extend <a href="http://download.oracle.com/javaee/6/api/javax/faces/application/ViewHandlerWrapper.html" rel="noreferrer"><code>ViewHandlerWrapper</code></a> instead.</li> <li>Not necessary, but just for cleanup, remove any Facelets 1.x related <code>&lt;context-param&gt;</code> values from <code>web.xml</code> which are already default in Facelets 2.0, like the <code>javax.faces.DEFAULT_SUFFIX</code> with value of <code>*.xhtml</code>.</li> <li><p>Update root declaration of existing Facelet taglib XML's to comply Facelets 2.0.</p> <pre class="lang-xml prettyprint-override"><code>&lt;facelet-taglib 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-facelettaglibrary_2_0.xsd" version="2.0"&gt; </code></pre></li> </ul> <p>That should basically be it.</p> <hr> <h2>JSP 2.x to Facelets 2.0</h2> <p>If you're using <strong>JSP 2.x</strong> as view technology and you want to upgrade to <strong>Facelets 2.0</strong> immediately, then you need to do a lot of changes before the site can go live. You're basically changing the view technology here. </p> <h3>Master page changes</h3> <p>On every master page, you need to change the following basic JSP template..</p> <pre class="lang-xml prettyprint-override"><code>&lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt; &lt;%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%&gt; &lt;%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%&gt; &lt;!DOCTYPE html&gt; &lt;f:view&gt; &lt;html lang="en"&gt; &lt;head&gt; &lt;title&gt;JSP page&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;h:outputText value="JSF components here." /&gt; &lt;/body&gt; &lt;/html&gt; &lt;/f:view&gt; </code></pre> <p>..to the following basic Facelets template:</p> <pre class="lang-xml prettyprint-override"><code>&lt;!DOCTYPE html&gt; &lt;html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets"&gt; &lt;h:head&gt; &lt;title&gt;XHTML page&lt;/title&gt; &lt;/h:head&gt; &lt;h:body&gt; &lt;h:outputText value="JSF components here." /&gt; &lt;/h:body&gt; &lt;/html&gt; </code></pre> <h3>Include page changes</h3> <p>If your existing JSP pages are well designed, you should not have any line of <em>scriptlet</em> code and you should also have only the <code>&lt;jsp:include&gt;</code> as the sole JSP-specific tag. Any of those needs to be changed from:</p> <pre class="lang-xml prettyprint-override"><code>&lt;jsp:include page="include.jsp" /&gt; </code></pre> <p>to</p> <pre class="lang-xml prettyprint-override"><code>&lt;ui:include src="include.xhtml" /&gt; </code></pre> <p>The basic JSP include page template of..</p> <pre class="lang-xml prettyprint-override"><code>&lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt; &lt;%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%&gt; &lt;%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%&gt; &lt;f:subview id="include"&gt; &lt;h:outputText value="JSF components here." /&gt; &lt;/f:subview&gt; </code></pre> <p>..should be changed to the following basic Facelets include page template:</p> <pre class="lang-xml prettyprint-override"><code>&lt;ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets"&gt; &lt;h:outputText value="JSF components here." /&gt; &lt;/ui:composition&gt; </code></pre> <h3>Custom component changes</h3> <p>You need to change the JSP TLD files to Facelets TLD files as described in this <a href="http://javaserverfaces.java.net/nonav/rlnotes/2.0.0/migration.html" rel="noreferrer">Mojarra Migration Guide</a>.</p> <hr> <h2>Aftermath</h2> <p>Regardless of the migration approach, you can gradually <a href="http://blogs.oracle.com/rlubke/entry/faces_config_xml_we_don" rel="noreferrer">eliminate</a> the <code>faces-config.xml</code> by the new JSF 2.0 annotations. Any <code>&lt;managed-bean&gt;</code> can be annotated by <a href="http://download.oracle.com/javaee/6/api/javax/faces/bean/ManagedBean.html" rel="noreferrer"><code>@ManagedBean</code></a>:</p> <pre><code>@ManagedBean(name="managedBeanName") @RequestScoped public class SomeBean {} </code></pre> <p>Next to <a href="http://download.oracle.com/javaee/6/api/javax/faces/bean/RequestScoped.html" rel="noreferrer"><code>@RequestScoped</code></a>, there are also <a href="http://download.oracle.com/javaee/6/api/javax/faces/bean/ViewScoped.html" rel="noreferrer"><code>@ViewScoped</code></a>, <a href="http://download.oracle.com/javaee/6/api/javax/faces/bean/SessionScoped.html" rel="noreferrer"><code>@SessionScoped</code></a> and <a href="http://download.oracle.com/javaee/6/api/javax/faces/bean/ApplicationScoped.html" rel="noreferrer"><code>@ApplicationScoped</code></a> available. If you omit the <code>name</code> attribute of the <code>@ManagedBean</code>, then it will default to classname with the 1st char lowercased. </p> <pre><code>@ManagedBean @RequestScoped public class SomeBean {} </code></pre> <p>In this particular example, it will be <code>#{someBean}</code>.</p> <p>Any <code>&lt;managed-property&gt;</code> can be annotated using <a href="http://download.oracle.com/javaee/6/api/javax/faces/bean/ManagedProperty.html" rel="noreferrer"><code>@ManagedProperty</code></a>:</p> <pre><code>@ManagedProperty("#{otherBean}") private OtherBean otherBean; </code></pre> <p>Any <code>&lt;validator&gt;</code> can be annotated using <a href="http://download.oracle.com/javaee/6/api/javax/faces/validator/FacesValidator.html" rel="noreferrer"><code>@FacesValidator</code></a>:</p> <pre><code>@FacesValidator("someValidator") public class SomeValidator implements Validator {} </code></pre> <p>Any <code>&lt;converter&gt;</code> can be annotated using <a href="http://download.oracle.com/javaee/6/api/javax/faces/convert/FacesConverter.html" rel="noreferrer"><code>@FacesConverter</code></a></p> <pre><code>@FacesConverter("someConverter") public class SomeConverter implements Converter {} </code></pre> <p>Any <code>&lt;renderer&gt;</code> can be annotated using <a href="http://download.oracle.com/javaee/6/api/javax/faces/render/FacesRenderer.html" rel="noreferrer"><code>@FacesRenderer</code></a></p> <pre><code>@FacesRenderer(componentFamily="someComponentFamily", rendererType="someRendererType") public class SomeRenderer extends Renderer {} </code></pre> <p>Any <code>&lt;navigation-case&gt;</code> which uses the filename of the XHTML page as both <code>&lt;from-outcome&gt;</code> and <code>&lt;to-view-id&gt;</code> can be removed since this will be <a href="http://andyschwartz.wordpress.com/2009/07/31/whats-new-in-jsf-2/#navigation-implicit" rel="noreferrer">implicitly</a> done. This can be gradually done by changing all outcome values to match the filename of the target view.</p> <p>Finally, any session scoped bean which was been put in the session with the sole reason to retain the bean data in subsequent requests in the same tab/window can better be marked <code>@ViewScoped</code>, because this way the bean won't be affected when the enduser opens the same page in different tabs/windows.</p> <hr> <h2>Component libraries</h2> <p>Note that I don't take any 3rd party componant libraries like PrimeFaces/RichFaces/IceFaces into account in this answer, it would then be impossible to write a reliable answer since it basically boils down to "it depends". In general it's sufficient to just upgrade the component library to a -by themselves verified- JSF 2.0 compatible version as per their instructions. Best is to just write unit tests, run them before and after the upgrade and fix any issues individually. </p> <p>Here are at least some useful links with regard to migration of the specific component library:</p> <ul> <li><a href="http://community.jboss.org/wiki/RichFacesMigrationGuide33x-4xMigration" rel="noreferrer">RichFaces Migration Guide - 3.3.x to 4.x migration</a></li> <li><a href="http://wiki.icefaces.org/display/ICE/ICEfaces+1.x+Compatibility" rel="noreferrer">IceFaces 2 Wiki - IceFaces 1.x Compatibility Guide</a></li> </ul> <p>PrimeFaces has no migration guide for PrimeFaces 1.x to 2.x as PrimeFaces 1.x requires Facelets 1.x already, so you just have to follow Facelets 1.x to 2.x migration steps. However, there's a PrimeFaces <a href="http://code.google.com/p/primefaces/wiki/MigrationGuideFrom22to30" rel="noreferrer">2.x to 3.x migration guide</a> which might apply as well on migrating from PrimeFaces 1.x to 3.x. Tomahawk has also no migration guide. Basically the only which you need to change are the JARs and if necessary get rid of all <code>&lt;t:saveState&gt;</code> references on a request scoped bean by making the bean view scoped.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload