2

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?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
ScottM
  • 109
  • 1
  • 1
  • 14

2 Answers2

7

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:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
0

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).

Bhesh Gurung
  • 50,430
  • 22
  • 93
  • 142
  • Bean is Request Scope, therefore values were initialized to null. Switched tactics to using the following: – ScottM Nov 15 '11 at 19:55
  • @ScottM: It's good that your problem was solved. But looks like BalusC's answer was helpful in solving the problem so you should accept his answer. – Bhesh Gurung Nov 15 '11 at 20:03