Use of JavaBeans to provide dynamic values - Web Services
Learn about an adaptable approach which separates programming tasks from Web page design tasks. This strong conceptual model encourages good design, enables re-use of data definitions, and is well-suited to the construction of dynamic user interfaces. The authors also illustrate the particular challenges you might encounter when you dynamically change the analysis performed by Web pages. (This intermediate-level article was first published by IBM developerWorks, August 5, 2004, at http://www.ibm.com/developerWorks).
A common way to transfer information within and between JSPs is by using JavaBeans. Bean attribute values might be set using HTML form submission, or a variety of other means. Once set, those attribute values can be used to control aspects of the data-related tags.
In Listing 4, a JavaBean is given an id of salesChoices and given page scope. This bean might support a number of properties that have been set by various means, but in this case, we assume that the region attribute has been set by user input using an HTML form control. The includeFilter tag filters on the sales region dimension, and the value to be included is taken from the region attribute of our salesChoices bean.
Populating form fields with dynamic values
To make the example shown in Listing 4, the page author will need to construct a page where the user can select the region from a list of current regions. The page author might choose to hard code a set of known sales region values. This is an acceptable strategy if the set of valid sales regions is fixed. However, if the list of current regions is volatile, or the list of regions that will be returned in the data varies according to other selections, the page author will wish to present the user with region choices that reflect the current state.
To meet this requirement, provide custom JSP tags can that produce HTML form controls populated with the appropriate values. You can obtain these values from the data source by leveraging the existing data definition.