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:

  1. Drag one of the selection list components to your Faces JSP page.
  2. Open the Properties view for the selection list component.
  3. 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.
  4. 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.
  5. In addition to static choices, you can add dynamic choices to the selection component. Dynamic choices get their value from your data source.
    1. Click Add Choice or Add Set of Choices. An entry is added to the Name column.
    2. To edit the name of the entry, click the name in the Name column so that you can edit it.
    3. 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.
    4. 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.
    5. 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: 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:
Related tasks
Creating an input form connected to a data source
Adding input components to a Faces JSP page
Adding hyperlinks to a Faces JSP file
Using navigation rules with Faces JSP pages
Using File Upload components
Managing errors in JavaServer Faces applications
Creating a Faces JSP file

Feedback