Reputation: 109
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
?
Upvotes: 2
Views: 12169
Reputation: 1108782
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.
Upvotes: 7
Reputation: 51030
If it's working when assigning "122334" but when assigning flightInfoController.flight.number
it's "null" and since you are not receiving any exception, then it means probably your flightInfoController
is not properly initialized (regarding it's field flight
and hence number
in the flight
).
Just make sure the bean is properly initialized (or update your OP with the bean code).
Upvotes: 0