Portlet Factory, Version 6.1.2


 

Retrieving multiple input values from a Checkbox Group builder

You can retrieve multiple input values from a Checkbox Group builder for use in a model by creating a iterator in the Method builder.

 

Using an iterator

A Checkbox Group builder will submit multiple values with the same name. If you request the value of the checkbox input, you will always retrieve only the first value, unless you use an iterator for the input values. Create an iterator by writing some code in the Method builder. The following code gets an Iterator for the input values passed by a Checkbox builder. Call this method when you submit the page with the Checkbox Group builder.

 

Iterator code sample

You will want to modify the code for your particular application. This code assumes that the model has two Variable builders in it named displayData and selectedData. It also assumes that the Checkbox Group builder was placed on a tag named checkboxTag. The final action of the method is to display a page called page1. You should change the code if you do not have a page1 or if you want to do something other than display a page called page1.

{
// Get an Iterator for the checkbox group inputs Iterator i = webAppAccess.getRequestInputs().getInputValues("checkboxTag");

// Get the Xml variable used to store the input values from the checkbox group
IXml displayData = webAppAccess.getVariables().getXml("displayData");

// Remove the data so that the variable is clean for every submission
// otherwise the code will continue to add new rows each time without removing the old ones displayData.removeChildren();

// We also have a variable to be used for the selected data in the checkbox group.
// Here we set this String Variable to an empty string webAppAccess.getVariables().setString("selectedData","");

// We also set a local variable to an empty string String selectedData = "";
 String separator = "";

// Use a while loop to run through the Iterator while(i.hasNext())
// Create a new row each time through
IXml newRow = XmlUtil.create("Row");

// Get the current value from the Iterator String value = (String)i.next();

// append each value to the selectedData String variable selectedData = selectedData + separator + value;

// set the value element of the new row to the current value from the Iterator newRow.setText("value",value);

// add the new row to the Xml variable displayData.addChildElement(newRow); separator = ",";
// Set the selectedData Variable to the value of the local variable that was built up in the while loop webAppAccess.getVariables().setString("selectedData",selectedData);

// Return page1 webAppAccess.processPage("page1");

} 

Parent topic: Checkbox Group builder


Library | Support |