0

What I do now:

call an action method

            <p:commandButton value="Fine"  
                             action="#{dtIndexBean.forwardAction}"  
                             styleClass="ui-priority-primary" 
                             ajax="false">  
                    <f:param name="result" value="fine"/>  
            </p:commandButton>

in forwardAction method, validate the input and forward to another view if validation goes fine

        String result =  FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("result");

            if (result.equals("wrong")) {
                System.out.println("WRONG!!");

            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, 
                            "", "WRONG!!"));
            return "";

        } else{
            paramBean.putForwardParameter("message", "Hello!");
            return "forwarded.xhtml";
        } 

I need to pass some parameters to forwarded view, now I put them in a session bean (here its name is "paramBean") so I can read them in the backing bean of the forwarded view:

String message;

    @PostConstruct
    private void init(){
        message = paramBean.getParameter("message");
        paramBean.clearForwardParameter();
    }

I only feel that this is clumsy due to the presence of an additional bean. Is there a less clumsy way to do this?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Frizz1977
  • 1,121
  • 13
  • 21
  • you can fine the example at https://www.dropbox.com/s/ia4fa9naeppjka7/Test-Forwarding-portlet.war?dl=0 – Frizz1977 Apr 21 '15 at 08:02
  • Maybe with `return "forwarded.xhtml?message=blabla"` ? – Jaqen H'ghar Apr 21 '15 at 09:54
  • 1
    Is the `forwardParameter` something you need to keep private? Then, the [flash scope](http://stackoverflow.com/questions/11194112/understand-flash-scope-in-jsf2) does exactly what you're looking for. If not, you could go with @JaqenH'ghar's answer – Aritz Apr 21 '15 at 10:40
  • The flash scope is a good solution, cleaner than mine. Unfortunately "forwarded.xhtml?message=blabla" doesn't work... – Frizz1977 Apr 28 '15 at 07:27

0 Answers0