Java Reference
In-Depth Information
Notice that we added a method called calculatePrice() at the end of the class.
This method will calculate a new price based on user selections. Also notice that
each setter method invokes this method. This will have the effect of updating the
price every time a user makes a selection on one of the drop-down components. We
also defined some constants in the ApplicationBean1.java application scoped
JSF managed bean. These constants are used to calculate the new price. We placed
these constants in an application scoped bean since they will be the same for every
user in the application. Had we put them in a session scoped bean, then there would
be a separate copy of these constants for each user, which wouldn't use the server
memory efficiently.
The constants defined in ApplicationBean1.java are very simple
and straightforward, therefore they are not shown. The full source for the
example can be found in the topic's source code download.
Next, we need to place the appropriate components into the design window of the
page, add the options for each drop-down as usual, and bind the values of each
component to the appropriate property in SessionBean1.java .
It is important to bind the properties to be used in an Ajax call to
properties to a JSF managed bean with a scope of session, since binding
them to a request scoped managed bean may result in values being lost
between Ajax requests.
 
Search WWH ::




Custom Search