f:setPropertyActionListener sets null value instead of intended value

12,026

If the #{flightInfoController.flight.number} is request scoped, then it has to preserve exactly the same flight in during the request of processing the form submit as it was during the request of displaying the form. This has to happen in the bean's (post)constructor.

If that is not an option, because it depends on some request based variables, then your best bet is to put the bean in the view scope instead (I however still assume that your bean is properly designed that it doesn't do any business/preloading job in getters).

If putting the bean in the view scope is in turn not an option, then you'd need to pass it as a fullworthy request parameter instead. You can do that by <f:param>.

<h:commandLink value="BookFlight" action="#{bookSeatController.doLoginOrCC}">
   <f:param name="flightNumber" value="#{flightInfoController.flight.number}" />
</h:commandLink>

You can let JSF set it by @ManagedProperty in the BookSeatController or by <f:viewParam> in the current view.

See also:

Share:
12,026
ScottM
Author by

ScottM

Software Devloper.

Updated on June 18, 2022

Comments

  • ScottM
    ScottM almost 2 years

    My view is:

    <h:commandLink value="BookFlight" action="#{bookSeatController.doLoginOrCC}">
       <f:setPropertyActionListener target="#{bookSeatController.flightNumber}" 
                      value="#{flightInfoController.flight.number}" />
    </h:commandLink>
    

    My setter is:

    public void setFlightNumber(String flightNumber) {
       this.flightNumber = flightNumber;
    }
    

    When I use the debugger I get a flightNumber of null in the setter. However, if I change the view to the following:

    <h:commandLink value="BookFlight" action="#{bookSeatController.doLoginOrCC}">
       <f:setPropertyActionListener target="#{bookSeatController.flightNumber}" 
                      value="122334" />
    </h:commandLink>
    

    The flightNumber property is set to 122334. How is this caused and how can I solve it to set the intended value instead of null?