【问题标题】:pretty faces does not work漂亮的面孔不起作用
【发布时间】:2015-02-11 13:51:45
【问题描述】:

我用我的 jsf 应用程序尝试了漂亮的面孔。URL 没有改变。我按照网站上提到的步骤进行操作。
pom.xml

<dependency>
    <groupId>org.ocpsoft.rewrite</groupId>
    <artifactId>rewrite-servlet</artifactId>
    <version>2.0.12.Final</version>
</dependency>
<dependency>
    <groupId>org.ocpsoft.rewrite</groupId>
    <artifactId>rewrite-config-prettyfaces</artifactId>
    <version>2.0.12.Final</version>
</dependency>

我在 WEB-INF/
中添加了 pretty-config.xml 漂亮的配置.xml

    <pretty-config xmlns="http://ocpsoft.org/schema/rewrite-config-prettyfaces" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xsi:schemaLocation="http://ocpsoft.org/schema/rewrite-config-prettyfaces
                      http://ocpsoft.org/xml/ns/prettyfaces/rewrite-config-prettyfaces.xsd">

    <url-mapping id="login">
        <pattern value="/login" />
        <view-id value="/pages/unsecure/login.jsf" />
    </url-mapping>


</pretty-config>

我的本​​地项目网址(完整网址)

http://localhost:9080/projectName/pages/unsecure/login.jsf

我使用 myfaces2.2.7、spring/security、hibernate、tomcat7
我需要做其他设置吗?我错过了什么。我不明白。
我到底应该怎么做?提前谢谢..

更新
我没有收到任何错误。只是不起作用。网址不变..

【问题讨论】:

    标签: jsf jsf-2.2 myfaces prettyfaces


    【解决方案1】:

    浏览器中的 URL 不会自动更改。 PrettyFaces 将漂亮的 URL 映射到内部 URL。因此,如果您要求:

    http://localhost:9080/projectName/login
    

    您实际上会看到配置中指定的/pages/unsecure/login.jsf 页面。使用 JSF 导航或内部重定向到此页面的导航将自动使用漂亮的 URL。

    如果您想从外部请求自动从内部 URL 重定向到漂亮的 URL(就像在您的示例中一样),那么您需要添加一个重写条件来做到这一点:

        <pretty-config xmlns="http://ocpsoft.org/schema/rewrite-config-prettyfaces" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xsi:schemaLocation="http://ocpsoft.org/schema/rewrite-config-prettyfaces
                          http://ocpsoft.org/xml/ns/prettyfaces/rewrite-config-prettyfaces.xsd">
    
        <url-mapping id="login">
            <pattern value="/login" />
            <view-id value="/pages/unsecure/login.jsf" />
        </url-mapping>
    
        <rewrite match="/pages/unsecure/login.jsf" substitute="/login" redirect="301"/>
    
    </pretty-config>
    

    或者,您可以使用Join 规则直接将Rewrite 用于这些规则中的两个(因为您已经在使用带有 PrettyFaces 扩展的 Rewrite):

    @RewriteConfiguration
    public class ExampleConfigurationProvider extends HttpConfigurationProvider
    {
       @Override
       public int priority()
       {
         return 10;
       }
    
       @Override
       public Configuration getConfiguration(final ServletContext context)
       {
         return ConfigurationBuilder.begin()
           .addRule(Join.path("/login").to("/pages/unsecure/login.jsf").withInboundCorrection());
        }
    }
    

    注意.withInboundCorrection() 方法调用。这会自动设置从 OLD url 到 NEW url 的入站重定向。

    我希望这会有所帮助。干杯!

    【讨论】:

      猜你喜欢
      • 2015-11-24
      • 2012-01-26
      • 2017-09-13
      • 2011-05-25
      • 2015-03-30
      • 2010-11-18
      • 2012-11-12
      • 2012-10-18
      • 1970-01-01
      相关资源
      最近更新 更多