views:

49

answers:

1

I have a client who wants to use JSF2 and they like that XHTML is now the default (Facelets).

However, they have a huge amount of "legacy" JSP from their JSF1.x codebase.

I know it's probably not desirable, but will it be possible to support a mix of both in JSF2, at least for a transition period whilst they port?

I know it was possible to mix the two in JSF1.x, but I can't find any information about this in JSF2.

I've googled hard but naturally all the JSF2 focus is on Facelets. Also my brief attempt at mixing (I'm not an expert at JSF!) has led to failure.

+1  A: 

This is answered in the Facelets FAQ: use prefix mapping on FacesServlet. You can then access JSP pages by http://example.com/faces/page.jsp and Facelets pages by http://example.com/faces/page.xhtml. Here's a cite of relevance:

How do I use Facelets and JSP in the same application?

You have to use prefix mapping for the Facelets pages in order for this to work. Leave the DEFAULT_SUFFIX with the JSF default of .jsp. Configure the Facelet's VIEW_MAPPINGS parameter:

<web-app>
    <context-param>
        <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
        <param-value>.jsp</param-value>
    </context-param>

    <!-- Facelets pages will use the .xhtml extension -->
    <context-param>
        <param-name>facelets.VIEW_MAPPINGS</param-name>
        <param-value>*.xhtml</param-value>
    </context-param>     

    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    </servlet>

    <!-- Use prefix mapping for Facelets pages, e.g. http://localhost:8080/webapp/faces/mypage.xhtml -->
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>
</web-app>
BalusC
Ah thankyou. I had seen that page but discounted it as I thought it was JSF1.x and out of date. I had tried a similar strategy as the web.xml above with a failure - problem my stupid mistake. Will retry thanks!
Dick Chesterwood