erginduran
erginduran

Reputation: 1682

pretty faces does not work

I tried pretty faces with my jsf app.URL has not changed.I followed the steps mentioned on the site.
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>

I added pretty-config.xml in WEB-INF/
pretty-config.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>

my local project url(full url)

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

I use myfaces2.2.7,spring/security,hibernate,tomcat7
Is there another setting I need to do?What I'm missing.I dont understand.
What exactly should I do?Thanks in advance..

UPDATE:
I don't get any error.just does not work. URL does not change..

Upvotes: 1

Views: 2241

Answers (1)

Lincoln
Lincoln

Reputation: 3191

The URL in the browser isn't going to change automatically. PrettyFaces maps pretty URLs to internal URLs. So if you request:

http://localhost:9080/projectName/login

You would actually see the /pages/unsecure/login.jsf page as specified in the configuration. Navigation using JSF navigation or internal redirects to this page will automatically use the pretty URL.

If you want to automatically redirect from the internal URL to the pretty URL from external Requests (like in your example,) then you need to add a rewrite condition to do that:

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

Alternatively, you can use Rewrite directly for both of these rules (since you are already using Rewrite with the PrettyFaces extension), using the Join rule:

@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());
    }
}

Note the .withInboundCorrection() method call. This sets up the inbound redirect from the OLD url to the NEW url automatically.

I hope this helps. Cheers!

Upvotes: 3

Related Questions