java - Migrating from JSF 1.2 to JSF 2.0 -


i working rather large app written in jsf 1.2. jsf 1.2 around 6 years old now. need upgrade jsf 2.0. how painful be? noticed attributes in custom tags have been changed etc.

painfulness

painfulness of upgrading jsf 1.2 2.0 depends on view technology using , want use.

  • jsp 2.x jsp 2.x = no effort.
  • facelets 1.x facelets 2.0 = little effort.
  • jsp 2.x facelets 2.0 = lot of effort. double if have custom components.

basic changes

regardless of view technology switch, at least following steps should done:

  • remove jsf 1.2 jar's /web-inf/lib (if any).
  • drop jsf 2.0 jar's in /web-inf/lib (if jsf 1.2 servletcontainer-supplied, might want change classloading policy load webapp libraries first before servletcontainer libraries, see jsf2 classloading issues in application servers).
  • update root declaration of faces-config.xml comply jsf 2.0 spec.

    <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"> 
  • ensure root declaration of web.xml complies at least servlet 2.5. jsf 2.0 won't work on 2.4 or lower (although it's hackable).

    <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"> 

jsp 2.x jsp 2.x

if you're using jsp 2.x , want keep using it, don't need change else.

gradually upgrading

if you're using suffix url-pattern facesservlet, *.jsf, it's know facesservlet first scan *.xhtml file , if not present, scan *.jsp file. provides room gradually convert jsp facelets behind scenes without changing url's.

but if you're using prefix url-pattern, /faces/* , want gradually upgrade jsp facelets, have change *.jsf , possibly links in existing jsp pages.

you need keep in mind new jsf 2.0 provided implicit navigation doesn't scan presence of file, go outcome.xhtml anyway. if want come or go *.jsp, still need include in viewid jsf 1.x way.


facelets 1.x facelets 2.0

if you're using facelets 1.x view technology , want use jsf 2.0 supplied facelets 2.0, need following additional steps:

  • remove facelets 1.x jar /web-inf/lib.
  • remove facelets 1.x faceletviewhandler faces-config.xml.
  • any custom faceletviewhandler implementation needs updated extend viewhandlerwrapper instead.
  • not necessary, cleanup, remove facelets 1.x related <context-param> values web.xml default in facelets 2.0, javax.faces.default_suffix value of *.xhtml.
  • update root declaration of existing facelet taglib xml's comply facelets 2.0.

    <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"> 

that should it.


jsp 2.x facelets 2.0

if you're using jsp 2.x view technology , want upgrade facelets 2.0 immediately, need lot of changes before site can go live. you're changing view technology here.

master page changes

on every master page, need change following basic jsp template..

<%@page contenttype="text/html" pageencoding="utf-8"%> <%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%> <%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%> <!doctype html> <f:view>     <html lang="en">         <head>             <title>jsp page</title>         </head>         <body>             <h:outputtext value="jsf components here." />         </body>     </html> </f:view> 

..to following basic facelets template:

<!doctype html> <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">     <h:head>         <title>xhtml page</title>     </h:head>     <h:body>         <h:outputtext value="jsf components here." />     </h:body>   </html> 

include page changes

if existing jsp pages designed, should not have line of scriptlet code , should have <jsp:include> sole jsp-specific tag. of needs changed from:

<jsp:include page="include.jsp" /> 

to

<ui:include src="include.xhtml" /> 

the basic jsp include page template of..

<%@page contenttype="text/html" pageencoding="utf-8"%> <%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%> <%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%> <f:subview id="include">     <h:outputtext value="jsf components here." /> </f:subview> 

..should changed following basic facelets include page template:

<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">     <h:outputtext value="jsf components here." /> </ui:composition> 

custom component changes

you need change jsp tld files facelets tld files described in mojarra migration guide.


aftermath

regardless of migration approach, can gradually eliminate faces-config.xml new jsf 2.0 annotations. <managed-bean> can annotated @managedbean:

@managedbean(name="managedbeanname") @requestscoped public class somebean {} 

next @requestscoped, there @viewscoped, @sessionscoped , @applicationscoped available. if omit name attribute of @managedbean, default classname 1st char lowercased.

@managedbean @requestscoped public class somebean {} 

in particular example, #{somebean}.

any <managed-property> can annotated using @managedproperty:

@managedproperty("#{otherbean}") private otherbean otherbean; 

any <validator> can annotated using @facesvalidator:

@facesvalidator("somevalidator") public class somevalidator implements validator {} 

any <converter> can annotated using @facesconverter

@facesconverter("someconverter") public class someconverter implements converter {} 

any <renderer> can annotated using @facesrenderer

@facesrenderer(componentfamily="somecomponentfamily", renderertype="somerenderertype") public class somerenderer extends renderer {} 

any <navigation-case> uses filename of xhtml page both <from-outcome> , <to-view-id> can removed since implicitly done. can gradually done changing outcome values match filename of target view.

finally, session scoped bean been put in session sole reason retain bean data in subsequent requests in same tab/window can better marked @viewscoped, because way bean won't affected when enduser opens same page in different tabs/windows.


component libraries

note don't take 3rd party componant libraries primefaces/richfaces/icefaces account in answer, impossible write reliable answer since boils down "it depends". in general it's sufficient upgrade component library -by verified- jsf 2.0 compatible version per instructions. best write unit tests, run them before , after upgrade , fix issues individually.

here @ least useful links regard migration of specific component library:

primefaces has no migration guide primefaces 1.x 2.x primefaces 1.x requires facelets 1.x already, have follow facelets 1.x 2.x migration steps. however, there's primefaces 2.x 3.x migration guide might apply on migrating primefaces 1.x 3.x. tomahawk has no migration guide. need change jars , if necessary rid of <t:savestate> references on request scoped bean making bean view scoped.


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -