0

I am trying to gradually move a project over to Facelets from .jsp, but am having a lot of trouble to say the least.

The current jsf tags are being rendered just fine on the .jsp pages.

The .xhtml page with a simple

<!DOCTYPE html>
 <html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:rich="http://richfaces.org/rich"
          xmlns:ui="http://java.sun.com/jsf/facelets"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:p="http://primefaces.org/ui"> 

           <h:head>
                <title>This is a Test</title>    
             </h:head> 

           <h:body>
           <div>
                <H2>
                    <h:outputText value="test"/>
                </H2>
                </div>
        </h:body>
</html>

the title gets rendered when trying to access the page directly (somePage.xhtml) but the JSF tags are never parsed (Inspecting the page shows JSF components and not the html).

When trying to use the virtual URL (somePage.cps) neither the title nor JSF tags are rendered. (Nothing is displayed on page inspection)

What I have been reading is this is because the JSF tags are not being passed through FacesServlet .

In my web.xml I have

    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.cps</url-pattern>
    </servlet-mapping>

Let me say I am new to JSF and this project was handed down to me, it is useing the virtual url pattern of .cps.

I have tried fixes mentioned here

Migrating from JSF 1.2 to JSF 2.0

and here

Mixing JSP and XHTML (Facelets) in JSF2 Project - possible?

** *******FULL WEB.XML********** **

<?xml version="1.0" encoding="UTF-8"?>


<web-app version="2.5" 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-app_2_5.xsd">
    <display-name>Copyright 2012 University of Kentucky</display-name>
    <context-param>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>server</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.CONFIG_FILES</param-name>
        <param-value>/WEB-INF/config/jsf/faces-config.xml</param-value>
    </context-param>
    <context-param>
        <param-name>org.ajax4jsf.DEFAULT</param-name>
        <param-value>classic</param-value>
    </context-param>
    <!-- Define the basename for a resource bundle for I18N -->
    <context-param>
        <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
        <param-value>messages</param-value>
    </context-param>
    <!-- Plugging the "Blue Sky" skin into the project -->

    <context-param>
        <param-name>org.richfaces.SKIN</param-name>
        <param-value>glassX</param-value>
    </context-param>

    <context-param>
        <param-name>org.apache.myfaces.ERROR_HANDLER</param-name>
        <param-value>edu.uky.cepis.util.global.error.JSFCustomErrorHandler</param-value>
    </context-param>

    <!-- Making the RichFaces skin spread to standard HTML controls -->
    <context-param>
        <param-name>org.richfaces.CONTROL_SKINNING</param-name>
        <param-value>enable</param-value>
    </context-param>

    <!-- 1. Setup two parameters: -->
    <!-- b) Logging configuration file -->
    <!-- b) Spring configuration file -->
    <context-param>
        <param-name>log4jConfigLocation</param-name>
        <param-value>/WEB-INF/classes/log4j.properties</param-value>
    </context-param>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/config/spring/cepis-*</param-value>
    </context-param>

    <context-param>
        <param-name>contextFactory</param-name>
        <param-value>
            com.tonbeller.wcf.controller.RequestContextFactoryImpl
        </param-value>
    </context-param>

    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.cps</url-pattern>
    </servlet-mapping>


    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>

    <!-- Defining and mapping the RichFaces filter -->
    <filter>
        <display-name>RichFaces Filter</display-name>
        <filter-name>richfaces</filter-name>
        <filter-class>org.ajax4jsf.Filter</filter-class>
        <init-param>
            <param-name>createTempFiles</param-name>
            <param-value>false</param-value>
        </init-param>
        <init-param>
            <param-name>maxRequestSize</param-name>
            <param-value>100000000</param-value>
        </init-param>
    </filter>
    <!-- Filter for AJAX4JSF <filter> <filter-name>ajax4jsf</filter-name> <filter-class>org.ajax4jsf.Filter</filter-class> 
        </filter> -->
    <filter>
        <filter-name>hibernateViewFilter</filter-name>
        <filter-class>
            org.springframework.orm.hibernate4.support.OpenSessionInViewFilter
        </filter-class>
    </filter>

    <filter>
        <filter-name>struts</filter-name>
        <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
    </filter>

    <filter>
        <filter-name>ResponseOverrideFilter</filter-name>
        <filter-class>org.displaytag.filter.ResponseOverrideFilter</filter-class>
    </filter>

    <filter>
        <filter-name>JPivotController</filter-name>
        <filter-class>com.tonbeller.wcf.controller.RequestFilter</filter-class>
        <!-- <init-param> <param-name>indexJSP</param-name> <param-value>/index.html</param-value> 
            <description> forward to this page if session is new </description> </init-param> 
            <init-param> <param-name>errorJSP</param-name> <param-value>/error.jsp</param-value> 
            <description>URI of error page</description> </init-param> <init-param> <param-name>busyJSP</param-name> 
            <param-value>/busy.jsp</param-value> <description> This page is displayed 
            if a the user clicks on a query before the previous query has finished </description> 
            </init-param> <init-param> <param-name>forceExtension</param-name> <param-value>.faces</param-value> 
            <description>replace .jsp with .faces</description> </init-param> -->
    </filter>
    <filter>
        <filter-name>MyFacesExtensionsFilter</filter-name>
        <filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>
        <init-param>
            <param-name>uploadMaxFileSize</param-name>
            <param-value>100m</param-value>
            <!-- <description>Set the size limit for uploaded files.Format: 10 - 10 
                bytes 10k - 10 KB 10m - 10 MB 1g - 1 GB</description> -->
        </init-param>
        <init-param>
            <param-name>uploadThresholdSize</param-name>
            <param-value>100k</param-value>
        </init-param>
    </filter>


    <filter>
        <filter-name>Spring character encoding filter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
        <init-param>
            <param-name>forceEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>


    <!-- Richfaces 3.3.3 Firefox 11 Patch -->
    <filter>
        <filter-name>RichFacesFirefox11Filter</filter-name>
        <filter-class>edu.uky.cepis.filter.patch.RichFacesFirefox11Filter</filter-class>
    </filter>


    <filter-mapping>
        <filter-name>hibernateViewFilter</filter-name>
        <url-pattern>*.cps</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>richfaces</filter-name>
        <servlet-name>Faces Servlet</servlet-name>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>FORWARD</dispatcher>
        <dispatcher>INCLUDE</dispatcher>
    </filter-mapping>
    <!-- <filter-mapping> <filter-name>ajax4jsf</filter-name> <servlet-name>Faces 
        Servlet</servlet-name> </filter-mapping> -->
    <filter-mapping>
        <filter-name>JPivotController</filter-name>
        <url-pattern>/jpivot.action</url-pattern>
    </filter-mapping>

    <filter-mapping>
        <filter-name>JPivotController</filter-name>
        <url-pattern>/JPivot.jsp</url-pattern>
    </filter-mapping>

    <filter-mapping>
        <filter-name>ResponseOverrideFilter</filter-name>
        <url-pattern>*.action</url-pattern>
    </filter-mapping>

    <filter-mapping>
        <filter-name>struts</filter-name>
        <url-pattern>/pages/report/*</url-pattern>
    </filter-mapping>

    <!-- Do not remove this. Needed for proper functioning of struts -->
    <filter-mapping>
        <filter-name>struts</filter-name>
        <url-pattern>/struts/*</url-pattern>
    </filter-mapping>

    <filter-mapping>
        <filter-name>Spring character encoding filter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <!-- extension mapping for adding <script/>, <link/>, and other resource 
        tags to JSF-pages -->
    <filter-mapping>
        <filter-name>MyFacesExtensionsFilter</filter-name>
        <servlet-name>Faces Servlet</servlet-name>
    </filter-mapping>
    <filter-mapping>
        <filter-name>MyFacesExtensionsFilter</filter-name>
        <url-pattern>/faces/*</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>RichFacesFirefox11Filter</filter-name>
        <url-pattern>*.cps</url-pattern>
    </filter-mapping>

    <!-- resources initializer -->
    <listener>
        <listener-class>
            com.tonbeller.tbutils.res.ResourcesFactoryContextListener
        </listener-class>
    </listener>

    <!-- 3. Setup three listeners -->
    <!-- a) Setup a listener to connect spring with the web context -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <listener> 
        <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class> 
    </listener>
    <listener>
        <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
    </listener>
    <!-- b) Setup a listener to connect spring with log4J -->
    <listener>
        <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
    </listener>
    <!-- c) Setup ACEGI to subscribe to http session events in the web context 
        <listener> <listener-class>org.acegisecurity.ui.session.HttpSessionEventPublisher</listener-class> 
        </listener> -->
    <listener>
        <listener-class>org.springframework.web.util.WebAppRootListener</listener-class>
    </listener>
    <!-- Spring Security Concurrent Session Listener -->
    <listener>
        <listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
    </listener>

    <!-- CAS Authentication -->
    <!-- <servlet> <servlet-name>casproxy</servlet-name> <servlet-class>edu.yale.its.tp.cas.proxy.ProxyTicketReceptor</servlet-class> 
        </servlet> -->
    <!-- Faces Servlet -->


    <!-- Servlet for Report Module -->
    <servlet>
        <servlet-name>JspSupportServlet</servlet-name>
        <servlet-class>org.apache.struts2.views.JspSupportServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet>
        <servlet-name>fileServlet</servlet-name>
        <servlet-class>org.efs.openreports.dispatcher.FileDispatcher</servlet-class>
        <load-on-startup>99</load-on-startup>
    </servlet>

    <servlet>
        <servlet-name>MondrianXmlaServlet</servlet-name>
        <servlet-class>org.efs.openreports.dispatcher.XMLADispatcher</servlet-class>
    </servlet>

    <servlet>
        <servlet-name>XFireServlet</servlet-name>
        <servlet-class>org.codehaus.xfire.spring.XFireSpringServlet</servlet-class>
    </servlet>

    <!-- jfreechart provided servlet -->
    <servlet>
        <servlet-name>DisplayChart</servlet-name>
        <servlet-class>org.jfree.chart.servlet.DisplayChart</servlet-class>
    </servlet>

    <!-- jfreechart provided servlet -->
    <servlet>
        <servlet-name>GetChart</servlet-name>
        <servlet-class>com.tonbeller.jpivot.chart.GetChart</servlet-class>
    </servlet>
    <servlet>
        <servlet-name>Print</servlet-name>
        <servlet-class>com.tonbeller.jpivot.print.PrintServlet</servlet-class>
    </servlet>

    <!-- EPSB Coldfusion access using Railo -->
    <servlet>
        <servlet-name>CFMLServlet</servlet-name>
        <servlet-class>railo.loader.servlet.CFMLServlet</servlet-class>
        <init-param>
            <param-name>configuration</param-name>
            <param-value>{web-root-directory}/WEB-INF/railo/</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet>
        <servlet-name>SpringServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath*:/org/springframework/batch/admin/web/resources/servlet-config.xml,classpath*:/org/springframework/batch/admin/web/resources/webapp-config.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>




    <!-- CAS Servlet Mapping -->
    <!-- <servlet-mapping> <servlet-name>casproxy</servlet-name> <url-pattern>/casProxy/*</url-pattern> 
        </servlet-mapping> -->
    <!-- Faces Servlet Mapping -->

    <servlet-mapping>
        <servlet-name>DisplayChart</servlet-name>
        <url-pattern>/DisplayChart</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Print</servlet-name>
        <url-pattern>/Print</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>GetChart</servlet-name>
        <url-pattern>/GetChart</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>fileServlet</servlet-name>
        <url-pattern>/report-images/*</url-pattern>
    </servlet-mapping>

    <servlet-mapping>
        <servlet-name>fileServlet</servlet-name>
        <url-pattern>/report-files/*</url-pattern>
    </servlet-mapping>

    <servlet-mapping>
        <servlet-name>XFireServlet</servlet-name>
        <url-pattern>/services/*</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>MondrianXmlaServlet</servlet-name>
        <url-pattern>/xmla</url-pattern>
    </servlet-mapping>


    <servlet-mapping>
        <servlet-name>CFMLServlet</servlet-name>
        <url-pattern>*.cfm</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>CFMLServlet</servlet-name>
        <url-pattern>*.cfml</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>CFMLServlet</servlet-name>
        <url-pattern>*.cfc</url-pattern>
    </servlet-mapping>
    <!-- Spring Batch Admin -->
    <servlet-mapping>
        <servlet-name>SpringServlet</servlet-name>
        <url-pattern>/batch/*</url-pattern>
    </servlet-mapping>


    <session-config>
        <session-timeout>15</session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>index.cps</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>


</web-app>
Community
  • 1
  • 1
Curt
  • 2,774
  • 6
  • 24
  • 34

1 Answers1

0

Remove the following context parameters (don't forget to first undo the incorrect changes proposed by Stephan).

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

<context-param>
    <param-name>javax.faces.FACELETS_VIEW_MAPPINGS</param-name>
    <param-value>*.xhtml</param-value>
</context-param> 

The first one is basically telling that JSF should use JSP as default view technology and hereby Facelets is never recognized/used. You certainly don't want to have that. The second one is the default already, but has no effect if the first one is set that way. Just remove them both. JSF 2.0 defaults to Facelets (XHTML) already. Also, when Facelets is been used as default view technology, then JSP is automatically used as "fallback". See also Migrating from JSF 1.2 to JSF 2.0. Don't only look at the steps or code examples, but also carefully read the text.

Community
  • 1
  • 1
BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
  • So with the "Suffix URL Pattern" of ` Faces Servlet *.cps ` This should scan for both .xhtml and .jsp? – Curt Sep 26 '12 at 13:27
  • Yes. It does that by default (see also my answer in "Migrating fro JSF 1.2 to JSF 2.0"). As you initially have with the wrong `javax.faces.DEFAULT_SUFFIX` value, it only scans for JSP. Just remove it altogether. – BalusC Sep 26 '12 at 13:28
  • This goes back to my original problem where it does not seem to be parsing the JSF components (title is rendered but ` – Curt Sep 26 '12 at 13:34
  • (When inspecting the page I can just see the jsf component and not the html ) – Curt Sep 26 '12 at 13:36
  • Then that means that the request URL did not match the `` of the `FacesServlet`. Provided that you have undo'ed the changes proposed by Stephen, then you should just open the XHTML by `/filename.cps` in browser and not by `/filename.xhtml`. – BalusC Sep 26 '12 at 13:38
  • when trying the filename.cps neither the title nor the h:output text are rendered (When inspecting the page, there is nothing). – Curt Sep 26 '12 at 13:41
  • Are the .xhtml pages not being "changed" to .cps...? Or something of the like? – Curt Sep 26 '12 at 13:50
  • May I assume that you have undo'ed the changes proposed by Stephen? My answer was targeted on your initial question. The "complete" web.xml which you posted afterwards still contains the wrong changes. As to your last comment, I'm not sure if I understand you. The `*.cps` is just an virtual URL pattern on which the `FacesServlet` has to be executed (and thus all JSF works has to be performed). The actual view file itself should still have the `.xhtml` extension, of course, exactly like as it was with `.jsp` files. Aren't you the original developer or so? Is this an inherited project or so? – BalusC Sep 26 '12 at 13:52
  • I apologize for not being more clear, I have un-done the changes proposed by Stephen, like I have said I am new to JSF I thought I properly understood the virtual URL but was not sure. And yes I inherited this project. – Curt Sep 26 '12 at 13:55
  • I have updated the original post and removed the changes suggested by Stephen. – Curt Sep 26 '12 at 14:00
  • In all honesty, you've pretty a lot of potential disturbances in your `web.xml`. As first step, to exclude JSF itself from being the cause, I suggest to remove (backup) *all* entries **expect of** the `` and `` of the `FacesServlet`. So your `web.xml` should end up like `......` with alone the servlet definition and servlet mapping of `FacesServlet` on `*.cps`. Then, retry to open the page by `/filename.cps`. Pay close attention to server logs. – BalusC Sep 26 '12 at 14:02
  • I just removed everything from the web.xml and after re-deploying and trying to re-open the page there has been no change, I am looking at the server logs and do not see anything obvious... Once again thanks for your help! – Curt Sep 26 '12 at 14:13
  • Okay. Did you properly remove all JSF 1.x and Facelets 1.x JARs from `/WEB-INF/lib`, if any? – BalusC Sep 26 '12 at 14:17
  • ahhh there was jsf-facelets1.1.14 was still on the build path after removing it from the pom.xml... frustrating, now however after removing it I am getting the following error `SEVERE: Exception starting filter richfacesjavax.servlet.ServletException: Error parse web application config` – Curt Sep 26 '12 at 15:06
  • The removal of the JAR file is already mentioned in that "Migrating JSF 1.2 to 2.0" answer. Try reading more carefully in the future. As to your new problem, I assume that this is with the full `web.xml`? Well, the cause is elsewhere. Try once again with the minimal `web.xml` as described before to exclude JSF2/Facelets itself from being suspect. – BalusC Sep 26 '12 at 15:08
  • Ok somehow the web.xml was changed...I reverted back to the old and am STILL having the same issue that I started with – Curt Sep 26 '12 at 15:11
  • Do you have any other ideas by chance, any direction to go in? – Curt Sep 26 '12 at 18:17