2012-10-15 31 views
2

我需要将pretty faces与我的jsf 2.0,primefaces应用程序集成,但它带来一些麻烦。与jsf集成蛮力的麻烦

正如getting started我放在我的web.xml以下提到,添加lib文件夹中所需的罐子在我的web.xml

<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> 

其他项目

<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.

回答

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将使用prettyfaces-jsf2.jar中包含的web-fragment.xml自动注册过滤器。

您不必在任何地方指定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 
+0

我正在使用servlet版本2.5。我想我已经遵循了你提到的所有事情。我会检查我是否错过了一些东西。 thnx很多!尝试后我会更新/评论。 –

+0

在这种情况下,您正确添加了过滤器(没有异步支持)。所以如果你在控制台上看到“PrettyFilter started”,并且在你的WEB-INF中有一个正确的pretty-config.xml,那么一切都应该正常工作。 :) – chkal

+0

也,如果我使用漂亮的网址,我的ManagedBeans应该实现'Serializable'吗? –