4-8 Java EE Developers Guide for Oracle Application Development Framework
4.2.3 What You May Need to Know About Setting the Current Row in a Table
When you use tables in an application and you allow the ADF Model layer to manage row selection, the current row is determined by the iterator. When a user selects a row
in an ADF Faces table, the row in the table is shaded, and the component notifies the iterator of the selected row. To do this, the selectedRowKeys attribute of the table is
bound to the collection model’s selected row, as shown in
Example 4–4 .
Example 4–4 Selection Attributes on a Table
af:table value={bindings.Products1.collectionModel} var=row .
. .
selectedRowKeys={bindings.Products.collectionModel.selectedRow} selectionListener={bindings.Products.collectionModel.
makeCurrent} rowSelection=single
This binding binds the selected keys in the table to the selected row of the collection model. The selectionListener attribute is then bound to the collection model’s
makeCurrent property. This binding makes the selected row of the collection the
current row of the iterator.
Although a table can handle selection automatically, there may be cases where you need to programmatically set the current row for an object on an iterator.
You can call the getKey method on any view row to get a Key object that encapsulates the one or more key attributes that identify the row. You can also use a
Key object to find a view row in a row set using the findByKey. At runtime, when
either the setCurrentRowWithKey or the setCurrentRowWithKeyValue built-in operation is invoked by name by the data binding layer, the findByKey method is
used to find the row based on the value passed in as a parameter before the found row is set as the current row.
The setCurrentRowWithKey and setCurrentRowWithKeyValue operations both expect a parameter named rowKey, but they differ precisely by what each expects that
rowKey parameter value to be at runtime:
sortable Determines whether
a column can be sorted.
Set to false. When set to true, the iterator binding will access the iterator to determine
the order. headerText
Determines the text displayed at the top
of the column. An EL expression that, by default, evaluates to
the label control hint set on the corresponding attribute.
Note: If you create a custom selection listener, you must create a
method binding to the makeCurrent property on the collection model for example,
{binding.Products.collectionModel.makeCurrent} and
invoke this method binding in the custom selection listener before any custom logic.
Table 4–1 Cont. ADF Faces Table Attributes and Populated Values
Attribute Description
Default Value
Creating ADF Databound Tables 4-9
The setCurrentRowWithKey Operation setCurrentRowWithKey
expects the rowKey parameter value to be the serialized string representation of a view row key. This is a hexadecimal-encoded string that looks
like this: 000200000002C20200000002C102000000010000010A5AB7DAD9
The serialized string representation of a key encodes all of the key attributes that might comprise a view rows key in a way that can be conveniently passed as a single
value in a browser URL string or form parameter. At runtime, if you inadvertently pass a parameter value that is not a legal serialized string key, you may receive
exceptions like oracle.jbo.InvalidParamException or java.io.EOFException
as a result. In your web page, you can access the value of the serialized string key of a row by referencing the rowKeyStr property of an ADF
control binding for example. {bindings.SomeAttrName.rowKeyStr} or the row variable of an ADF Faces table for example, {row.rowKeyStr}.
setCurrentRowWithKeyValue The setCurrentRowWithKeyValue operation expects the rowKey parameter value
to be the literal value representing the key of the view row. For example, its value would be simply 201 to find product number 201.
4.3 Creating an Editable Table
You can create a table that allows the user to edit information within the table, and then commit those changes to the data source. To do this, you use operations that can
modify data records associated with the returned collection or the data control itself to create command buttons, and place those buttons in a toolbar in the table. For
example, the table in the browse.jspx page has a button that allows the user to remove a product. While this button currently causes a dialog to display that allows
the user to confirm the removal, the button could be bound to a method that directly removes the product.
As with editable forms, it is important to note that the ADF Model layer is not aware that any row has been changed until a new instance of the collection is presented.
Therefore, you need to invoke the execute operation on the accessor iterator in order for any changes to be committed. For more information, see
Section 2.3.4, What You May Need to Know About Iterator Result Caching.
When you decide to use editable components to display your data, you have the option of having the table displaying all rows as editable at once, or having it display
all rows as read-only until the user double-clicks within the row. Figure 4–3
shows a table whose rows all have editable fields. The page is rendered using the components
that were added to the page for example, inputText, inputDate, and inputNumberSpinbox
components.
Tip: To create a table that allows you to insert a new record into the
data store, see Section 4.4, Creating an Input Table.