FacesMessage not displayed when redirect using prettyfaces

Splash Forums PrettyFaces Users FacesMessage not displayed when redirect using prettyfaces

This topic contains 4 replies, has 2 voices, and was last updated by  Christian Kaltepoth 6 years, 9 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #17848

    timotius_pamungkas
    Participant

    Hi, I’m new on prettyfaces. Currently I have developed a website, http://www.adsafari.us, using Primefaces + Prettyfaces.

    The prettyfaces was added lately on simple URLs, however I get something weird regarding faces message. My faces message (using primefaces p:message) was not displayed when I redirect page from action method. When i use something like this (returns JSF 2 implicit navigation), the message was displayed correctly:

    public String doSomething() {

    FacesMessage facesMessage = new FacesMessage(….)

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

    return “/pages/member/home.jsf”;

    }

    but when I change the return value into “pretty:member_home”, navigation was redirected to proper page, but no message displayed. I guess this is something related with faces-redirect, but i don’t know how to display the message.

    Here is the pretty-config.xml

    <url-mapping id=”member_home”>

    <pattern value=”/member/home” />

    <view-id>/pages/member/home.jsf</view-id>

    </url-mapping>

    Is there any way to correctly display message?

    Thank you

    #20581

    Unfortunately this is expected behavior. As the redirect results in a completely new request which is independent of the original request that generated the messages, these won’t be rendered on the page.

    However there is a workaround for this issue. Lincoln wrote a PhaseListener that saves the messages in the session and restores them when the following request is received. To use this listener, just add the following lines to your faces-config.xml:

    <lifecycle>
    <phase-listener>com.ocpsoft.pretty.faces.event.MultiPageMessagesSupport</phase-listener>
    </lifecycle>

    I guess we should really mention this in the documentation. :-)

    #20582

    timotius_pamungkas
    Participant

    i’ll try it at once, thanks

    but when you said “saves the messages in the session”, will that means that session size will be very large?

    #20583

    No, the messages are saved just before the redirect is sent and then restored when the new request arrives. After that they will be immediately removed from the session. So they won’t increase the session size.

    #20584
Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

Comments are closed.