0
votes

I try to pass a parameter (or even an object) to a faces flow. But all articles I found, they are passing parameters from one flow to another. I want to pass the parameter from a simple request which is starting the flow.
How can I achieve this? What is best practice?

Here is a sample:

<p:commandLink action="regularDemand">
***<!-- <f:param name="paramName" value="paramValue" /> -->***
    <p:panel header="Header" style="height: 300px;">
         <p:outputLabel value="Some text." />
    </p:panel>
</p:commandLink>

regularDemand is the Name of the flow, which is called.

1

1 Answers

0
votes

I don't know if this is the unique way but I did it using flash.

I have a bean like this:

public class CreateAdBean {
    public String createAd(Integer adId) {
        if (adId != null) {
            FacesContext.getCurrentInstance().getExternalContext().getFlash().put("adId", adId);
        }
    }

    return "adFlow";
}

When I want to start a flow with a parameter I call this bean method passing the parameter, put it in the flash and return the flow name, in this case, "adFlow", which starts the flow.

In the first flow page, adFlow.xhtml, I have a <f:metadata/> calling a method that uses the parameter in the flash:

<f:metadata>
      <f:event type="preRenderView" listener="#{adFlowBean.loadExistingAd()}"/>
</f:metadata>

In the flow bean I do:

public class AdFlowBean {
    public void loadExistingAd() {
        Integer id = (Integer) FacesContext.getCurrentInstance().getExternalContext().getFlash().get("adId");
         if (id != null) {
             //do something with the parameter
         }
    }
}

I hope this help.