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 4 years, 8 months ago.

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

    Carolina
    Member

    Hi,

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

    XHTML:

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

    pretty-config.xml:

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

    #23034

    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:

    http://ocpsoft.org/docs/prettyfaces/3.3.3/en-US/html/navigation.html

    #23035

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

    #23036

    Carolina
    Member

    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.

    @lincoln,

    encodeURL(…) can resolve the issue?

    #23037

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

    #23038

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

    #23039

    Carolina
    Member

    Thanks Lincoln,

    Its working fine.

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

You must be logged in to reply to this topic.

Comments are closed.