Conversation Scope not working with redirect

1.1k Views Asked by At

I'm working with JSF and PrettyFaces and I need to do the next thing. I have 4 buttons generated in an ui:repeat. Every commandButton sets an object in a Conversation Bean and then I have to navigate to another page and get the object that was set in the button clicked. It seems pretty simple but the problem is I need a PrettyFaces friendly URL in the browser.

Tests done:

  • If I put the xhtml resource as string in the return commandbutton action navigates correctly but the URL points to the xhtml resource, not to the pretty-faces friendly URL. (Ex: ...host/my-web/prices.xhtml)

  • If I put the friendly URL as string (/web/prices/) in the return commandbutton action is not navigating.

  • If I do a redirect as follows:

    FacesContext context = FacesContext.getCurrentInstance();
    HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();
    
    try {
         context.getExternalContext().redirect("/web/prices/");
    

It navigates correctly to the friendly URL but the conversation is not working because before I redirect I'm setting the object recived in the commandbutton action and when navigates this object in the conversation bean is null.

Any idea how to solve that?

Thanks in advance.

1

There are 1 best solutions below

1
On

Looks like you're not adding the cid parameter to your redirects. That has to be passed via POST or query string in order for the conversation to continue. The value for that you can retrieve from an injected Conversation object.