Can I use pretty faces URL rewrite in existing JSF-2.0 and Richfaces-3.3.3 app?

Splash Forums PrettyFaces Users Can I use pretty faces URL rewrite in existing JSF-2.0 and Richfaces-3.3.3 app?

This topic contains 11 replies, has 3 voices, and was last updated by  Lincoln Baxter III 4 years, 8 months ago.

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #18758

    Carolina
    Member

    Hi All,

    I have web application created by using JSF-2.0, Richfaces-3.3.3 and Spring-Core technologies.I need to mask the original URL to client readable URL (for SEO compatible as well). Can I use pretty faces without changing the existing technology configuration (Which is used in running application) for URL rewrite?

    Can I get any help or suggestion from Forum to achieve URL rewrite from pretty faces?

    #23020

    Yes, PrettyFaces should not impact your existing applications. If you ask a specific question about something you are having trouble with. We would be glad to be of assistance.

    #23021

    Carolina
    Member

    Thanks for spontaneous reply :)

    According to Pretty Faces document for JSF-2.0, I have configured the following things.

    1. pom.xml

    <dependency>

    <groupId>com.ocpsoft</groupId>

    <artifactId>prettyfaces-jsf2</artifactId>

    <version>3.3.2</version>

    </dependency>

    2. Added pretty faces filter at top in the web.xml.

    3. Created pretty-config.xml in web-inf folder. and i have added URL-Mapping as below

    <url-mapping id=”hotelloginNormal”>

    <pattern value=”/b2c/Login” />

    <view-id value=”/pages/hotel/hotelLoginNormal.xhtml” />

    </url-mapping>

    ‘b2c’ is my context root defined in jboss-web.xml.

    login page resides in this package ‘/pages/hotel/hotelLoginNormal.xhtml’

    And the navigation rule defied in faces-config.xml on click of login button as follows

    <navigation-rule>

    <navigation-case>

    <from-outcome>hotelloginNormal</from-outcome>

    <to-view-id>

    /pages/hotel/hotelLoginNormal.xhtml

    </to-view-id>

    <redirect></redirect>

    </navigation-case>

    </navigation-rule>

    Now I am expecting the URL in browser something like this.

    http://localhost:8080/b2c/Login

    Instead of ‘ http://localhost:8080/b2c/pages/hotel/hotelLoginNormal.xhtml ‘ (Which is original URL).

    But still I am getting original URL in my browser.

    May I know what is wrong in my configuration? Or I need to do any code changes for this?

    -Vishwa.

    #23022

    You should not include the context path in your pattern. So you should use something like this:

    <url-mapping id="hotelloginNormal">
    <pattern value="/Login" />
    <view-id value="/pages/hotel/hotelLoginNormal.xhtml" />
    </url-mapping>

    If you now access http://localhost:8080/b2c/Login in your browser, you should see your login page. Does it work this way?

    #23023

    Carolina
    Member

    Hi Christian,

    Grate it is working fine, when I type ‘ http://localhost:8080/b2c/Login ‘ in browser URL, its redirecting to login page, however in browser its again converting to original URL i.e ‘ http://localhost:8080/b2c/pages/hotel/hotelLoginNormal.xhtml ‘.

    Is there any solution to stop showing original URL to client and in browser the URL should remain as it is ( http://localhost:8080/b2c/Login) ?

    -Vishwa

    #23024

    You say that when entering http://localhost:8080/b2c/Login into your browser bar you get redirected to http://localhost:8080/b2c/pages/hotel/hotelLoginNormal.xhtml? That is not correct. You shouldn’t be redirected but the real login page should render without any redirect.

    Are you perhaps using some security framework that detects that you are not logged in and redirects you to the old login page?

    #23025

    Carolina
    Member

    Hi Christian,

    Yes its redirection to original URL instead of showing only “http://localhost:8080/b2c/Login&#8221; in browser.

    I have not used any security framework, Only I have added navigation rule in faces-config.xml as below.

    Please find an attached web.xml as well

    <navigation-rule>

    <navigation-case>

    <from-outcome>hotelloginNormal</from-outcome>

    <to-view-id>

    /pages/hotel/hotelLoginNormal.xhtml

    </to-view-id>

    <redirect></redirect>

    </navigation-case>

    </navigation-rule>

    This navigation calls on click of login button which has action attribute on h:commandButton.

    Java Bean Class action method:

    public String loginClick(){

    return “hotelloginNormal”;

    }

    pretty-config.xml:

    <url-mapping id=”hotelloginNormal”>

    <pattern value=”/b2c/Login” />

    <view-id value=”/pages/hotel/hotelLoginNormal.xhtml” />

    </url-mapping>

    Only above configuration I have.

    XHTML:

    <h:commandButton value=”Login” action=”#{loginBean.loginClick}”/>

    #23026

    Carolina
    Member

    Christian,

    I have found why its redirecting to original URL. I have added action tag in url-mapping as below.

    Once i have remove action tag, its working.

    However when I type ‘ http://localhost:8080/b2c/Login ‘ in browser the URL remain in browser without changing to original URL.

    But when the Login button click its going to login page with original URL only (in browser it showing ‘ http://localhost:8080/b2c/pages/hotel/hotelLoginNormal.xhtml ‘) instead of ‘ http://localhost:8080/b2c/Login

    I need to keep Navigation Rule in face-config.xml or not.

    Please let me know how should it work on click of button?

    <url-mapping id=”hotelloginNormal”>

    <pattern value=”/Login” />

    <view-id value=”/pages/hotel/hotelLoginNormal.xhtml” />

    <action>#{loginBean.loginClick}</action>

    </url-mapping>

    #23027

    Carolina
    Member

    At last I have achieved what I am expecting.

    Thanks Christian/Lincoln for your support and help.

    Now on click of login the URL rewrite is working.

    I have changed in the action method by redirecting ‘ preety:Login ‘ as below

    <url-mapping id=”Login”>

    <pattern value=”/b2c/Login” />

    <view-id value=”/pages/hotel/hotelLoginNormal.xhtml” />

    </url-mapping>

    public String loginClick(){

    return “pretty:Login”;

    ;

    }

    Once again thanks to Prettyfaces :)

    #23028

    The action tag in the XML configuration will instruct PrettyFaces to execute the action on EVERY request to the pretty URL. This is probably not what you want. So you should remove that tag from your configuration.

    I think your navigation rules in your faces-config.xml may lead to these problems. It is very uncommon to use navigation rules together with PrettyFaces. You should remove the navigation rules and instead use the PrettyFaces way of navigation from action methods like described here:

    http://ocpsoft.org/docs/prettyfaces/3.3.2/en-US/html/navigation.html#navigation.actions

    #23029

    Sorry, I didn’t refresh the page before I wrote my response. :)

    I’m glad to hear your solved your problem. :)

    #23030

    Great! Glad you got it working :)

    In general, you should avoid mixing JSF-navigation and Pretty-navigation. However, something else may have been preventing the mapping from correctly modifying the outbound URL. If this happens again, please let us know.

    ~Lincoln

Viewing 12 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic.

Comments are closed.