How to do POST-REDIRECT-GET after action with PrettyFaces ?

Splash Forums PrettyFaces Users How to do POST-REDIRECT-GET after action with PrettyFaces ?

This topic contains 16 replies, has 3 voices, and was last updated by  Christian Kaltepoth 9 years, 5 months ago.

Viewing 15 posts - 1 through 15 (of 17 total)
  • Author
  • #18125


    Hi OCPsoft PrettyFaces,

    With regular JSF + f:viewParam this is doable using:

    public String tellSkill() {

    // do something

    return “show?faces-redirect=true&includeViewParams=true”;


    However, with PrettyFaces I cannot make this work: (f:viewParam is removed from xhtml template)

    public String tellSkill() {

    // do something

    return “pretty:admin_users_show?faces-redirect=true”;


    pretty-config.xml is :

    <url-mapping id=”admin_users_show”>

    <pattern value=”/admin/users/#{ id : userShowView.userId }” />

    <view-id value=”/faces/admin/users/show.xhtml” />


    Whatever I do, I still get a normal postback. The URL is correct but I don’t get a redirect->get :(

    Help… :)


    You don’t need to append faces-redirect to the action outcome. PrettyFaces always navigates with POST-REDIRECT-GET. So just use:

    public String tellSkill() {
    // ...
    return "pretty:admin_users_show";

    This should do the trick.




    Unfortunately, I’m not getting the behavior you described. I always get a standard postback (the URL is prettyfied, so URL rewriting is working). I’m using PrettyFaces 3.3.2 on JBoss AS 7.0.2 with Servlet 3.0 web.xml.

    The template code is:



    <h:selectOneMenu value=”#{userShowView.relatedSkillId}”>

    <f:selectItems value=”#{skillsView.skills}” var=”skill” itemLabel=”#{}” itemValue=”#{skill.nodeId}”/>


    <h:commandButton action=”#{userShowView.tellSkill}” value=”Tell” />

    <h:commandButton action=”#{userShowView.seekSkill}” value=”Seek” />



    Are you sure that your action method gets invoked correctly? Did you add <h:messages> to the page? Perhaps there is a validation error on the page and so the action method doesn’t get invoked. In this case you would only see a postback without a redirect.



    @Christian : yes the action method is invoked.

    I also try using a4j:commandButton and it works (After clicking, I can refresh the page and Firefox will not “complain”) with a nice ajax effect.

    But I am still curious how to do it with normal h:commandButton with PrettyFaces.

    The only way I can manage it to work is by using JSF-style viewParam, returning “/admin/users/show?faces-redirect=true&includeViewParams=true” and PrettyFaces will rewrite the URL. This results in proper P-R-G and correct PrettyFaces URL. However it’s quite some work just to get a basic functionality.


    It is really very weird that you don’t see PRG behavior with PrettyFaces. Actually I never heard from somebody having problems with this.

    Could you tell us about what stack you are using: Container, JSF-Implementation, additional libraries. Do you use a custom ViewHandler or NavigationHandler?




    I want to commend the great work the PrettyFaces Team is doing. It’s indeed fabulous.

    I have been using PrettyFaces for a while now. The experience has been interesting. I however observed very recently that page navigations do not REDIRECT rather FORWARD. Is the situation? If it is, how can I redirect between pages.

    I will appreciate your kind assistance.

    Mojarra 2.1.7, Primefaces 3.4, Tomcat 7.0.27, PrettyFaces 3.3.2


    No, PrettyFaces uses redirects for navigation. Could you show us an example for which the redirect doesn’t work correct?



    This portion of code is in web.xml



    <filter-name>Pretty Filter</filter-name>





    <filter-name>Pretty Filter</filter-name>









    <?xml version=’1.0′ encoding=’UTF-8′?>

    <!– =========== FULL CONFIGURATION FILE ================================== –>

    <pretty-config xmlns=”″



    <url-mapping id=”setup”>

    <pattern value=”/setup/” />

    <view-id value=”/faces/setup/scheme-list.xhtml”/>


    <url-mapping id=”category”>

    <pattern value=”/category/” />

    <view-id value=”/faces/faq/categoryList.xhtml”/>


    <url-mapping id=”version”>

    <pattern value=”/version” />

    <view-id value=”/faces/faq/createVersion.xhtml”/>


    <url-mapping id=”user”>

    <pattern value=”/user/” />

    <view-id value=”/faces/administrator/viewAdminUser.xhtml”/>


    <url-mapping id=”mobileUser”>

    <pattern value=”/mobileUser/” />

    <view-id value=”/faces/usersession/viewUserSession.xhtml”/>


    <url-mapping id=”home”>

    <pattern value=”/home/”/>

    <view-id value=”/faces/process/generate-returns.xhtml”/>


    <url-mapping id=”login”>

    <pattern value=”/login/” />

    <view-id value=”/faces/index.xhtml”/>




    public String homePage() {

    return “pretty:home”;


    public String userInitiatelogout() {


    FacesMessage facesMessage = new FacesMessage(FacesMessage.SEVERITY_INFO, “Logout Request”, “User successfully logout”);

    FacesContext.getCurrentInstance().addMessage(null, facesMessage);

    return “pretty:login”;





    The pages navigate correctly. But the challenge experienced here is that when I log out and log in again the pages I have prior visited holds the old values. Investigation shows that this is possible only when pages forward to other pages. But this would not have been if pages redirect. PrettyFaces controls the navigations on my entire application.

    Did I miss anything in my configuration above?

    Kindly advise.



    You can very easily check whether PrettyFaces redirects correctly by using the development tools of your browser (like Firebug). If it is behaving correctly, you should see a 302 followed by a 200 for a request. If not, you will only see a 200 OK response. Could you check that?

    In case of an action outcome like “pretty:mappingId”, PrettyFaces will always perform a redirect. If not, there seems to be some issue in you application.


    Perhaps the “old values” are cause by some sort of scoping problem? Perhaps you beans have a scope which isn’t short enough?



    Hi @Christian,

    Thank you for your feedback. I have attempted your suggestions as requested above. I however can not lay my eyes on either of the status messages above (200 or 300) on firebug. I have attached the server log for your review.

    Another point of note is that all the managed beans are @RequestScoped. Does this have any impact the behaviour in any way? This behaviour is also maintained even on the login page. The pages tends to retain the user name.

    Any assistance is highly appreciated.



    I don’t think that the logs will help here. You must have a close look at the requests and response your browser sends and receives. Look at the following screenshot for an example for a typical POST-REDIRECT-GET like it happens if you return something like “pretty:myId” from an action method:

    View post on

    The first row is the postback to the server. It executes the action method which returns “pretty:myId”. PrettyFaces therefore sends a 302 response (=redirect) to the client telling the client to load the target page with a GET request. The browser does so in the second row. It is a normal GET request for the target page (which is in this example the same as the page the postback was send to).



    Hi @Christian,

    Please what version of firebug do you have. I can not see this output on mine.



    It’s version 1.10.2 which is the most recent version available. But this view already exists a long time in Firebug. You can find it in the “net” tab on the right.

Viewing 15 posts - 1 through 15 (of 17 total)

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

Comments are closed.