richfaces + index.xhtml having errors

末鹿安然 提交于 2019-12-11 09:15:18

问题


I have been unable to get my index.xhtml file to load properly, and I have checked all the tutorials for this. Can somebody please point me in the right direction? I was only going through the tutorials on the richfaces site.

Below is my web.xml file:

<?xml version="1.0"?>
<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>Greeter</display-name>

<context-param>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>server</param-value>
</context-param>

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

<context-param>
    <param-name>org.richfaces.CONTROL_SKINNING</param-name>
    <param-value>enable</param-value>
</context-param>

<filter>
    <display-name>RichFaces Filter</display-name>
    <filter-name>richfaces</filter-name>
    <filter-class>org.ajax4jsf.Filter</filter-class>
</filter>

<filter-mapping>
    <filter-name>richfaces</filter-name>
    <servlet-name>Faces Servlet</servlet-name>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>INCLUDE</dispatcher>
</filter-mapping>

<listener>
    <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>

<!-- Faces Servlet -->
<servlet>
    <servlet-name>Loader</servlet-name>
    <servlet-class>com.mounza.common.Loader</servlet-class>
    <load-on-startup>2</load-on-startup>
</servlet>
<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

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

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

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

<welcome-file-list>
    <welcome-file>index.jsf</welcome-file>
</welcome-file-list>

<session-config>
    <session-timeout>
        30
    </session-timeout>
</session-config>


回答1:


You're talking about the <welcome-file>, right? It must point to a physically existing file, because that's internally been used by the servletcontainer to show the default resource whenever a folder is been requested. The servletcontainer will first check if the file exists before performing a forward on this. If the file doesn't exist, you'll just get a 404.

Combining this with JSF which get executed on a virtual URL only requires a special trick. You basically need to fool the servletcontainer with a physically existing but empty index.jsf file there in the folder next to your real index.xhtml file. This way the servletcontainer won't show a 404, but perform a forward to the file which will automatically trigger the FacesServlet.

But if you happen to already use JSF 2.x (which doesn't seem to be the case, but anyway, just for sake of completeness), then you can also just change the URL pattern of the FacesServlet from *.jsf (and /faces/*) to *.xhtml. This way you do not need to fiddle with virtual URLs anymore. This is not possible in JSF 1.x, because the FacesServlet would keep calling itself in an infinite loop.



来源:https://stackoverflow.com/questions/9642356/richfaces-index-xhtml-having-errors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!