Home > Java > javaTutorial > What are the challenges of migrating from JSF 1.2 to JSF 2.0, and how do these challenges vary depending on the view technology used?

What are the challenges of migrating from JSF 1.2 to JSF 2.0, and how do these challenges vary depending on the view technology used?

Mary-Kate Olsen
Release: 2024-12-28 03:08:10
Original
632 people have browsed it

What are the challenges of migrating from JSF 1.2 to JSF 2.0, and how do these challenges vary depending on the view technology used?

The pain of upgrading from JSF 1.2 to JSF 2.0

The pain of upgrading from JSF 1.2 to 2.0 is based on the view technology you currently use and the future. It depends on the viewing technology you plan to use.

  • JSP 2.x to JSP 2.x = almost no effort.
  • Facelets 1.x to Facelets 2.0 = less effort.
  • JSP 2.x to Facelets 2.0 = A lot of work. Double that if you have custom components.

Basic Changes

Regardless of switching view technology, you should at least perform the following steps:

  • Remove the JSF 1.2 JAR from /WEB-INF/lib (if present).
  • Drop the JSF 2.0 JAR into /WEB-INF/lib (if JSF 1.2 was provided by a servlet container, set the class to load the web application libraries first before the servlet container's libraries). Consider changing the loading policy (see also Application Server JSF2 Class Loading Issues).
  • Update the root declaration in faces-config.xml to match the JSF 2.0 specification.
  <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">
Copy after login
Copy after login
Copy after login

Note: If you are using JSF 2.2 or later, use http://xmlns.jcp instead of http://java.sun.com throughout the XML snippet above. Use the .org namespace domain.

  • Ensure that the route declaration in web.xml is at least Servlet 2.5 compliant. JSF 2.0 will not work below 2.4 (though hacks are possible).
  <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"
     >
Copy after login
Copy after login
Copy after login

Note: If you are using Servlet 3.0 or higher, use http://xmlns.jcp instead of http://java.sun.com throughout the XML snippet above. Use the .org namespace domain.

JSP 2.x to JSP 2.x

If you are using JSP 2. Basically you don't need to change anything else. Gradual Upgrade

If you are already using a suffix URL pattern (such as

.jsf) for FacesServlet and want to

just use

, FacesServlet first scans for .xhtml files and if they don't exist, *.jsp It's a good idea to remember to scan your files. This allows for gradual conversion from JSP to Facelets without changing URLs.

However, if you are using a prefix URL pattern (e.g. /faces/) and want to upgrade from JSP to Facelets in stages, change it to .jsf and possibly replace the existing All links in the JSP page must also be changed.

Please note that the new JSF 2.0 provided implicit navigation does not scan for the existence of the file and navigates to outcome.xhtml anyway. So if you move from .jsp or to .jsp, you still need to include it in the view ID in the JSF 1.x way.

Facelets 1.x to Facelets 2.0

I am using Facelets 1.x as my view technology and Facelets 2.0<🎜 comes with JSF 2.0. > If you want to use it, you need to take the following additional steps:

    Remove the Facelets 1.x JAR from /WEB-INF/lib.
  • Facelets 1.x Remove FaceletViewHandler from faces-config.xml.
  • If you have a custom FaceletViewHandler implementation, you must update it to extend ViewHandlerWrapper.
  • Although unnecessary, for cleanup purposes, remove Facelets 1.x-related values ​​(e.g., javax.faces.DEFAULT_SUFFIX value is *.xhtml) from web.xml . This is already the default in Facelets 2.0.
  • Update the root declaration of your existing Facelet tag library XML to be Facelets 2.0 compliant.
  •   <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">
    Copy after login
    Copy after login
    Copy after login
    Note: If you are using JSF 2.2 or later, use http://xmlns.jcp instead of http://java.sun.com throughout the XML snippet above. Use the .org namespace domain.

    These are basically sufficient.

    JSP 2.x to Facelets 2.0

    We are using

    JSP 2.x as our view technology and will soon upgrade to Facelets 2.0 If you want to, you'll have to make a lot of changes before publishing your site. We're basically changing the view technique here.

    Master Page Modifications

    The following basic JSP template must be modified in all master pages.

      <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"
         >
    Copy after login
    Copy after login
    Copy after login
    Change to the following basic Facelets template.

      <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">
    Copy after login
    Copy after login
    Note: If you are using JSF 2.2 or later, use the http://xmlns.jcp.org name instead of http://java.sun.com throughout the XHTML snippet above. Use spatial domain.

    Include page changes

    If your existing JSP pages are well designed, there will be no scriptlet lines of code and the only JSP-specific tag will be They should be changed from:

      <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">
    Copy after login
    Copy after login
    Copy after login

    Change as follows.

      <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"
         >
    Copy after login
    Copy after login
    Copy after login

    Basic JSP include page template...

      <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">
    Copy after login
    Copy after login

    ... must be changed to the following basic Facelets include page 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>
    Copy after login

    The above is the detailed content of What are the challenges of migrating from JSF 1.2 to JSF 2.0, and how do these challenges vary depending on the view technology used?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template