使用PrettyFaces 3.3.1-SNAPSHOT

时间:2011-10-13 14:52:43

标签: jsf-2 prettyfaces

我下载了3.3.1-SNAPSHOT版本来制作通用网址 关于这篇文章:

Pretty Faces: Generic URL mapping

我的配置如下:

我的web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd&quot; id="WebApp_ID" version="2.5">
  <display-name>myapp</display-name>

  <listener>
    <listener-class>
        org.springframework.web.context.ContextLoaderListener
    </listener-class>
  </listener>

  <listener>
    <listener-class>
        org.springframework.web.context.request.RequestContextListener
    </listener-class>
  </listener>

  <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
        classpath:META-INF/spring/applicationContext.xml
        classpath:META-INF/spring/applicationSecurity.xml
        </param-value>

  </context-param>

  <!-- Activating the Expression Language -->
    <context-param>
        <param-name>com.sun.faces.expressionFactory</param-name>
        <param-value>com.sun.el.ExpressionFactoryImpl</param-value>
    </context-param>

  <context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Development</param-value>
  </context-param>

  <welcome-file-list>
    <welcome-file>users</welcome-file>
  </welcome-file-list>

  <context-param>
    <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>server</param-value>
  </context-param>

  <context-param>
    <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
    <param-value>resources.application</param-value>
  </context-param>

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

  <context-param>
    <param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
    <param-value>true</param-value>
  </context-param>

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

    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>FORWARD</dispatcher>
        <dispatcher>REQUEST</dispatcher>
    </filter-mapping>

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

  <servlet>
    <servlet-name>Resource Servlet</servlet-name>
    <servlet-class>com.icesoft.faces.webapp.CompatResourceServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>Resource Servlet</servlet-name>
    <url-pattern>/xmlhttp/*</url-pattern>
  </servlet-mapping>

  <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>/faces/*</url-pattern>
    <url-pattern>/icefaces/*</url-pattern>
  </servlet-mapping>

</web-app>

my pretty-config.xml:

<pretty-config xmlns="http://ocpsoft.com/prettyfaces/3.3.0"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://ocpsoft.com/prettyfaces/3.3.0
               http://ocpsoft.com/xml/ns/prettyfaces/ocpsoft-pretty-faces-3.3.0.xsd"&gt;

    <url-mapping id="generic">
    <pattern value="/*" />
    <view-id value="/faces/$1.xhtml" />
    </url-mapping>

</pretty-config>

以下行在终端中继续重复:

at com.ocpsoft.pretty.faces.config.annotation.WebClassesFinder.processDirectory(WebClassesFinder.java:183) at

1 个答案:

答案 0 :(得分:1)

Mika,

这不是PrettyFaces使用URL映射构造支持的东西,您必须改为使用自定义重写规则:

<rewrite match="/(.*)" substitute="/faces/$1.xhtml" />

但是,请考虑这样一条规则的影响(类似于上面定义的规则。)当然会有一个无限循环,因为“*”也匹配“/faces/XXX.xhtml”。您需要使匹配模式更具限制性。

<rewrite match="^/(.*)(?<!\.xhtml)$" substitute="/faces/$1.xhtml" />

我还建议您阅读正则表达式,因为“/ *”不是一个正则表达式,它会执行您认为它会执行的操作:http://ocpsoft.com/opensource/guide-to-regular-expressions-in-java-part-2/#lookaround

但是,如果你想要一个专门为执行这样的任务而设计的URL重写工具,那么我建议你看看OCPsoft Rewrite:http://ocpsoft.com/rewrite/,一个更强大(但更难以使用)的URL - 工具。

它允许你做这样的事情:

       .addRule(Join.path("/{page}")
                .to("/pages/{page}.xhtml")
                .when(Resource.exists("/pages/{page}.xhtml"))
                .where("page").matches("(?!RES_NOT_FOUND)[^/]+"))