Many users will attempt to get input values for the Checkbox Group builder, but are only able to get the value of the first checkbox in the group. In addition, when working with page automation, most inputs will automatically update the page automation variable. This is not the case for the Checkbox Group builder. The sample demonstrates how to retrieve ALL of the values for the input. This sample is also helpful when working with other builders that add input controls to a page, where the input control submits multiple values using the same name. Other builders that do this include Radio Button Group and the Select builder (when multi-select is enabled).
Here are some of the techniques illustrated in this sample:
- Getting values from a page control that submits multiple values.
- Using IXml to build up an IXml variable from the input values.
The trick to getting the multiple values is to get an Iterator rather than a single value for the input name. You can create an Iterator of the Checkbox values with the following code where "checkboxTag" is the name of the tag that I have attached my Checkbox Group builder to.
// Get an Iterator for the checkbox group inputs
Iterator i = webAppAccess.getRequestInputs().getInputValues("checkboxTag");
Notes on running the sample and prerequisites
Import the attached zip file into your project using the Import WebSphere Portlet Factory Archive command.
There are no special prerequisites for running this model. The work of getting the input values and building a variable is done in the getCheckboxValues method. Review the code in this method see how the values are retrieved.