URL rewriting on JSF ActionListener is not getting

Splash Forums PrettyFaces Users URL rewriting on JSF ActionListener is not getting

This topic contains 6 replies, has 3 voices, and was last updated by  Carolina 9 years, 4 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
  • #18770



    I have tried URL rewriting on JSF action-listener but still I am getting original URL in browser (‘ http://e125:8080/b2c/pages/hotel/hotelLoginNormal.xhtml?id=123 ‘) instead of

    http://e125:8080/b2c/Login/id=123 ‘ or http://e125:8080/b2c/Login/123

    Any idea what wrong in my code?

    Java Bean Code:

    public void loginClick(){		FacesUtils.getFacesContext().getExternalContext().redirect(FacesUtils.getFacesContext().getExternalContext().getRequestContextPath() + "/pages/hotel/hotelLoginNormal.xhtml?id="+123);


    <h:commandButton value="Login" actionListener="#{loginBean.loginClick}"/>


    <url-mapping id="Login">
    <pattern value="/Login/#{ id : loginBean.id }" />
    <view-id value="/pages/hotel/hotelLoginNormal.xhtml" />


    You should use an action method instead of an actionListener. Then you could do something like this:

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

    public void loginClick() {
    return "/pages/hotel/hotelLoginNormal.xhtml?faces-redirect=true&id="+123;

    Or this:

    public void loginClick() {
    loginBean.setId( 123 );
    return "pretty:Login";

    See this part of the documentation for details:



    Also, the reason your URL is not being encoded is because you did not call FacesUtils.getFacesContext().getExternalContext().encodeURL(...)



    Thanks Christian,

    However my application is existing application, and we have used action-listener lot of places and some time we need to redirect page from the action-listener method.

    Thats the reason without altering code much, I could tried to navigate (And URL rewrite) from the action-listener.

    If it is really not possible from action-listener then i will implement your way (With action) or is there any workaround it would be very great i can implement with action-listener.


    encodeURL(…) can resolve the issue?


    Yes, encodeURL should solve your problem. URL-encoding is something that must manually be invoked, and this is where Rewriting occurs.


    You can also simply redirect to the URL you wish to see :) then it should work anyway, but you should still encode the URL.



    Thanks Lincoln,

    Its working fine.

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

The forum ‘PrettyFaces Users’ is closed to new topics and replies.

Comments are closed.