我需要将pretty faces与我的jsf 2.0,primefaces应用程序集成,但它会带来一些麻烦。
如我在我的web.xml中放置的getting started中所述,在lib文件夹中添加了所需的jar
<filter>
<filter-name>Pretty Filter</filter-name>
<filter-class>com.ocpsoft.pretty.PrettyFilter</filter-class>
<async-supported>true</async-supported>
</filter>
<filter-mapping>
<filter-name>Pretty Filter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
我的web.xml中的其他项目
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<context-param>
<param-name>com.sun.faces.expressionFactory</param-name>
<param-value>org.jboss.el.ExpressionFactoryImpl</param-value>
</context-param>
<context-param>
<param-name>org.primefaces.extensions.DELIVER_UNCOMPRESSED_RESOURCES</param-name>
<param-value>false</param-value>
</context-param>
但是我得到了以下错误:
Invalid content was found starting with element 'async-supported'. One of '{"http://java.sun.com/xml/ns/javaee":init-param}' is expected
如果我从项目构建中删除<async-supported>
,项目编译但映射不起作用。
pretty-config.xml
与入门时相同。
我需要在web.xml中提及映射文件的名称/路径,即pretty-config.xml吗?
修改
我正在使用Glassfish服务器3。
答案 0 :(得分:5)
检查version
中使用的web.xml
属性非常重要。如果您设置了version="2.5"
,则必须将其添加到您的web.xml:
<filter>
<filter-name>Pretty Filter</filter-name>
<filter-class>com.ocpsoft.pretty.PrettyFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Pretty Filter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
请注意,此处未设置<async-supported>true</async-supported>
,因为它仅在Servlet 3.0中受支持。
如果您在web.xml中设置了version="3.0"
,则无需向web.xml添加任何内容。在这种情况下,PrettyFaces会使用web-fragment.xml
中包含的prettyfaces-jsf2.jar
自动注册过滤器。
您无需在任何地方指定pretty-config.xml
的位置。只需将其放在WEB-INF
文件夹中,PrettyFaces就会找到它。
您还应该向pretty-config.xml
添加一个映射,以便检查一切是否正常。例如,您有一个通常使用以下URL访问的页面:
http://localhost:8080/myapp/faces/login.xhtml
然后你可以添加这个映射:
<url-mapping id="login">
<pattern value="/login" />
<view-id value="/faces/login.xhtml" />
</url-mapping>
现在您应该可以使用以下链接访问该页面:
http://localhost:8080/myapp/login