0
votes

My environment is RAD 8, WAS 7.0.x with a lot of JSPs and Servlets. The application also uses JAX-RPC and JAX-WS I want to introduce JSF and start migrating some easier JSPs.

I have a huge issue that I can not migrate to JSF 2.0 straight away, because my target is WAS 7.x and I came across that it does not support JSF 2.0. I share the WAS 7.x with other business groups. So I have to use JSF 1.2 for now ..

In RAD 8, I tried following:

From an testJSF.jsp file, I used c:redirect to /faces/test1.jsp. I also tried jsp:forward to /faces/test1.jsp. Servlet-mapping has url-pattern entries for /faces/* and *.jsp This time WAS 7, gave me /test1.jsp not found...

Then I tried , from testJSF.jsp file, I used c:redirect to /faces/test1.jsf I also tried jsp:forward to /faces/test1.jsf. This time I also changed, Servlet-mapping with url-pattern entries for /faces/* and *.jsf This time WAS 7 went in an endless loop with stack overflow..

Under these environments, what should be url-pattern for servlet-mapping and how should I refer the new JSF 1.2 pages?

2

2 Answers

0
votes

You should be fine with JSF 2.0 as Websphere 7.0 implements the Servlet 2.5 spec (as far as I can see).

/faces/* or *.jsf mapping should be fine, there might be a configuration problem somewhere else... you need to provide more details.

Why do you need a .jsp to test a JSF page? What happens if you open the page directly from the browser?

0
votes

Servlet-mapping has url-pattern entries for /faces/ and .jsp

You should not specify a *.jsp mapping for FacesServlet. This pattern is reserved for the servlet container's builtin JspServlet. This way the FacesServlet can never get the right JSP file to present the view.


Servlet-mapping with url-pattern entries for /faces/ and .jsf This time WAS 7 went in an endless loop with stack overflow.

You should not give the actual view file a .jsf extension, but a .jsp extension.


The proper setup is the following:

  • Map the FacesServlet on alone *.jsf.

    <servlet>
        <servlet-name>facesServlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>facesServlet</servlet-name>
        <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>
    

    You can also use /faces/* instead, or add it, but this is uglier and does not allow for easy migration to JSF 2.0. So leave it away.

  • The view files should have the .jsp extension.

    viewid.jsp

    <%@taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
    <%@taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
    <!DOCTYPE html>
    <f:view>
        <html lang="en">
            <head>
                <title>JSF 1.2 test page</title>
            </head>
            <body>
                <h:outputText value="If you see this, JSF works!" />
            </body>
        </html>
    </f:view>
    
  • Do not use <c:redirect> or <jsp:forward>, this makes no utter sense. Just call the page by URL directly:

    http://localhost:8080/contextname/viewid.jsf

    Note the .jsf extension in the URL. This invokes the FacesServlet. It will then locate the viewid.jsp file and show it.

See also: