In general, you need to create an array that represents the options in the control, as well as a single variable to hold the value of the selected option. The simplest way to do this is by defining an array of strings and populating the array with the options for the control. See "Using an array of STRING as the selection options." Alternatively, you can use an array of records as the options for the control by specifying fields in the record as the option that is displayed in the control and as the value for the selection. See "Using an array of records as the selection options."
selectionOptions string[4];
selectionOptions string[4]
{"First choice", "Second choice",
"Third choice", "Fourth choice"};
selectedChoice string;
selectionOptions string[4]
{"First choice", "Second choice",
"Third choice", "Fourth choice",
SelectedValueItem = selectedChoice};
You can choose from Combobox (also called a list box or drop-down box), List Box - single select, or Radio Button Group. In each case, the options will be added dynamically depending on the number of elements in the list of options at run time.
You can check which variables the JSF control is bound to by clicking the control to select it and then opening the Properties view. In the Properties view, the Value field represents the variable that will receive the value of the selected option, and the table of variables at the right side of the view lists the variable or variables that are used to provide the options for the control.
handler singleSelect type JSFHandler
{view = "singleSelect.jsp"}
selectionOptions string[4]
{"First choice","Second choice",
"Third choice","Fourth choice",
SelectedValueItem = selectedChoice};
selectedChoice string;
outputMessage string;
function getChoice()
outputMessage = "You chose: "
+ selectedChoice;
end
end
This example assumes that you have dragged the selectionOptions variable
onto the page and created a combo box, list box, or radio button group
based on this variable. You will also need to bind the outputMessage variable
to an output control and the getChoice function to
a button on the page. When you click the button, the output control
displays the text of the option you selected in the JSF single-select
control.The method of using an array of strings as the selection options is simple, but it might not be the most convenient method. You might need to retrieve the options from an array of records, or you might need to use one value for the option and pass a different value to the selection result variable. In this case, use the @SelectionList record property to indicate which fields in the record should be used for the option and which should be used for the value of the selection.
To use an array of records as the selection options:
record optionsRec type BasicRecord
{@SelectionList {labelItem = displayOption,
valueItem = optionValue}}
displayOption string;
optionValue string;
end
The record can contain other fields, but you must select
two of these fields to be the label and the value.selectionOptions optionsRec[3];
function onPreRender()
selectionOptions[1].displayOption = "Option one";
selectionOptions[1].optionValue = "first option";
selectionOptions[2].displayOption = "Option two";
selectionOptions[2].optionValue = "second option";
selectionOptions[3].displayOption = "Option three";
selectionOptions[3].optionValue = "third option";
end
selectedChoice string;
The
type of this variable must match the type of the field marked as valueItem in
the Record part.selectionOptions optionsRec[3]
{selectedValueItem = selectedChoice};
You can choose from Combobox (also called a list or drop-down box), List Box - single select, or Radio Button Group. In each case, the options will be added dynamically depending on the number of elements in the list of selection options at run time.
You can check which variables the JSF control is bound to by clicking the control to select it and then opening the Properties view. In the Properties view, the Value field represents the variable that will receive the value of the selected option, and the table of variables at the right side of the view lists the variable or variables that are used to provide the options for the control.
handler singleSelect type JSFHandler
{view = "singleSelect.jsp",
onPreRenderFunction = onPreRender}
selectionOptions optionsRec[3]
{selectedValueItem = selectedChoice};
selectedChoice string;
outputMessage string;
function onPreRender()
selectionOptions[1].displayOption = "Option one";
selectionOptions[1].optionValue = "first option";
selectionOptions[2].displayOption = "Option two";
selectionOptions[2].optionValue = "second option";
selectionOptions[3].displayOption = "Option three";
selectionOptions[3].optionValue = "third option";
end
function getChoice()
outputMessage = "You chose: "
+ selectedChoice;
end
end
record optionsRec type BasicRecord
{@SelectionList {labelItem = displayOption,
valueItem = optionValue}}
displayOption string;
optionValue string;
end
This example assumes that you have dragged the selectionOptions variable
onto the page and created a combo box, list box, or radio button group
that is based on this variable. You also need to bind the outputMessage variable
to an output control and the getChoice function to
a button on the page. When you click the button, the output control
displays the text of the option that you selected in the JSF single-select
control.