Search code examples
jsfmyfaces

Pass parameter to the backing bean of the new page while navigation


I use a commandLink to navigate to another page:

<t:commandLink action="go_orderForm" immediate="true">
     <h:outputText value="#{order.number}" />
    <t:updateActionListener property="#{orderForm.orderId}"
                    value="#{order.id}" />
</t:commandLink>

This is working and setting the value of order.id to the backing bean orderForm.orderId.

In another place, I use a commandButton to call an action in the backing bean of the current page and navigate after to the new page:

<h:commandButton value="Create Batch" action="#{orderList.createBatchOrder}" />

The action in the backing bean looks like:

public String createBatchOrder() {
    // do something

    return "go_orderForm";
}

The faces-config.xml contains

<navigation-rule>
    <navigation-case>
        <from-outcome>go_orderForm</from-outcome>
        <to-view-id>/orderForm.jsp</to-view-id>
    </navigation-case>
</navigation-rule>

How can I pass the parameter for orderForm.orderId when I navigate using the action in the backing bean?


Solution

  • Before redirect put your parameter to flash:

    FacesContext.getCurrentInstance().getExternalContext().getFlash().put(key, value);
    

    After redirect you may get it by:

    FacesContext.getCurrentInstance().getExternalContext().getFlash().get(key);