Enabling row selection for a data table
You can add the ability for users to select one or more rows of your data table, and then perform actions on those rows.
After you have placed a data table on your page, you can then add row select support.
- Select the data table.
- On the Row actions tab of the Properties view for the data table, click Add next to "Add selection column to the table." A new column on the left side of the data table is added. This column contains a check box. (Note that the Add button changes to Remove in case you want to remove the row selection column later.)
- Select the check box in the new column.
- On the Properties view for inputRowSelect:
- You can set properties and styles on the check box or choose new images to use instead of the default check box.
- Click Add next to "Add selection toolbar" to add a selection toolbar to the footer of the data table. (You can also move the toolbar to the header.) With the selection toolbar, the user can select rows.
- Click Add next to "Add selection combo box" to add a selection combo box to the footer of the data table. (You can also move the combo box to the header.) With the selection combo box, the user can select all or none of the rows.
- Click the Parameter tab under inputRowSelect to add a parameter that associates the row select column with your data source. This also identifies the selected rows. The Properties view for inputRowSelect parameters opens.
- Click Add Parameter to add a parameter.
- Select the default parameter name to give it a new name.
- Select the value of the parameter and click the button that displays next to the value. The Select Page Data Object dialog opens.
- Select the field that is the primary key of the data table's data source and click OK. The row select is bound to the data source.
- Add one or more buttons to perform actions on the selected rows.
- Drag a Command - Button component (or Command - Hyperlink component) from the palette to the page.
- On the Display options tab of the Properties view for the button, enter the label for the button in the Button label field.
- Specify any other attributes for your button.
- Associate an action with a button by using the Quick Edit view for the button.
- To add a pre-coded action, such as Go To Page, Add Form, Update a Record, or Delete a Record, right-click the right pane of the Quick Edit view and select an action from the Insert Snippet menu.
- To code your own action, left-click the right pane of the Quick Edit view, delete the default code and add your own code.
- For examples of using an action to pass a parameter, see Passing parameters with a data table or Passing parameters between JSP pages.
The inputRowSelect component needs to have its value bound to one of the following object types. The value binding must be set to a non-null object. The RowSelect value is typically stored in a Java Bean. Note that the first three options in the following list of options perform more efficiently as the dataTable reloads the list object and makes it available to the action code. The value is used for both rendering and posting back.
- Boolean - Works with a property of the list object
<h:dataTable value="#{pc_opage.myList}" var="varmyList"> <h:column> <hx:inputRowSelect value="#{varmyList.selected}> </h:column> </h:dataTable>- Boolean[] or boolean[] - an array matching the list. If isSelected[4] is true, the the fifth element of the list was selected.
<h:dataTable value="#{pc_opage.myList}" var="varmyList"> <h:column> <hx:inputRowSelect value="#{pc_opage.isSelected}> </h:dataTable>- Integer[] or int[] - an array which contains the indexes of the selected elements of the list.
<h:dataTable value="#{pc_opage.myList}" var="varmyList"> <h:column> <hx:inputRowSelect value="#{pc_opage.selected}> <h:column> </h:dataTable>- Collection - Collection object (for example, ArrayList) which contains Map objects. Each Map has the set of name/value pairs defined by the parameter child tags for each selected element.
<h:dataTable value="#{pc_opage.myList}" var="varmyList"> <h:column> <hx:inputRowSelect value="#{pc_opage.selected}> <h:column> </h:dataTable>
Related concepts
JavaServer Faces
Data table components
Related tasks
Adding a data table
Adding header and footer to a data table
Associating row actions with a data table
Adding row category support to a data table
Adding row edit to a data table
parameter from one Faces JSP page to another. Several Faces components, such as command buttons or command hyperlinks, can help you do this">Passing parameters with a data table
Passing parameters between JSP files
Creating navigation for Faces JSP files
Related reference
Faces components reference
Faces attributes reference