Adding selection lists to a Faces JSP file
You can use several types of selection list components on a Faces JSP page. You can drag combo boxes, list boxes, radio buttons, and check boxes to your page and then dynamically bind them to your data source.
You can add the following selection list components. Note that they all have similar properties in their Properties views.
- Combo box (selectOneMenu): User chooses one item from a drop-down list.
- List box - Single Select (SelectOneListbox): User chooses one item from a list.
- List box - Multiple Select (SelectManyListbox): User can choose multiple items from a list.
- Radio Button Group (selectOneRadio): User selects one radio button from a list.
- Check Box (selectBooleanCheckbox): User checks or removes check from one item.
- Check Box Group (selectManyCheckbox): User checks one or more items from a list.
To add a selection component to your Faces JSP page:
- Drag one of the selection list components to your Faces JSP page.
- Open the Properties view for the selection list component.
- In the
Value field, you can bind to a data source so that the current value can be displayed or the value for a specific record field can be changed. For example, if you are creating a new employee record, you might have a selection list to choose the department or the city and the value you choose becomes part of the new employee record.
- For a check box or radio button, specify
Horizontal or
Vertical in the
Direction field of the Properties view, or accept the default. For a list box, specify the height in number of lines.
- In addition to static choices, you can add dynamic choices to the selection component. Dynamic choices get their value from your data source.
- Click
Add Choice or
Add Set of Choices. An entry is added to the
Name column.
- To edit the name of the entry, click the name in the
Name column so that you can edit it.
- If you want to bind the new entry to a data value, click within the
Value cell and then click the button that displays in the cell. The Select Page Data Object dialog opens.
- Select a property from a record list to bind to the choice or set of choices and click OK. (Note that the data source must already have been defined.) At run time, a list derived from your data source is displayed.
- To remove a choice, select the choice and click
Remove Choice. To move choices in the list, select the choice and click
Move Up or
Move Down.
Additional details:
For dynamic values, the list of choices is produced by one or more selectitem or selectitems tags. The value attribute of the selectitems tag points to the data element that contains the choices. The selectitems tag expects one of the following forms of data:
For any other data types, the tool generates a value to translate the data into one of these desired forms. The value will have the form selectitems.bean.label.value.toArray where:
- A java.util.Collection of javax.faces.component.SelectItem member objects. The SelectItem class defines a simple container that holds label, value, and description for an individual choice.
- An array of javax.faces.component.SelectItem
When you bind from the Page Data view, selecting an individual field always creates a value that uses the same field for both label and value. To use different strings for the UI label and passed value, modify the value manually according to the pattern above. Examples of value attributes for the selectitems tag:
- selectitems is a special keyword to identify this translation case
- bean identifies something JavaBean-like in the data model. It might be a multi-level reference such as aaa.bbb.ccc, and can resolve to any Object, including Collection types.
- label is a property of the object identified by bean. The value of this property is what is displayed as a choice.
- value is another property of bean and is set with the selected choice. By default, this is the same as label).
- toArray is a keyword to terminate the special reference string.
- myBean.choices binds a SelectItem[] property choices from a bean called myBean.
- selectitems.EMPLOYEES.NAME.NAME.toArray binds the String property NAME from a Data List called EMPLOYEES
- selectitems.anotherBean.choices.choices.toArray binds a String array called choices from a JavaBean called anotherBean.
- selectitems.EMPLOYEE.NAME.EMPID.toArray manually binds employee names from a Record List called EMPLOYEES, using the employee ID for the selected value.
Related reference