F: setPropertyActionListener sets to null instead of the intended value

My opinion:

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

My setter:

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

When I use the debugger, I get flightNumber from null in the customizer. However, if I changed the view to the following:

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

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

+2
source share
2 answers

If #{flightInfoController.flight.number} is the scope of the request, then it should keep exactly the same flight during the form processing request as it did during the form display request. This should happen in the bean (post) constructor.

If this is not an option, because it depends on some query-based variables, it is best to put the bean in scope instead (I still assume that your bean is properly designed, does not do any work / preload tasks in getters )

If you put a bean in the viewport, in turn, is not an option, then you will need to pass it as a fully functional query parameter. You can do this with <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 to @ManagedProperty in BookSeatController or <f:viewParam> in the current view.

See also:

+7
source

If it works when assigning "122334", but when assigning flightInfoController.flight.number "null", and since you are not getting any exception, it means your flightInfoController not been correctly initialized (relative to this flight field and hence the number in flight ).

Just make sure the bean is properly initialized (or update the OP with the bean code).

0
source

Source: https://habr.com/ru/post/1381299/


All Articles