What Happens When You Add a Table to a Page

10-26 Web User Interface Developers Guide for Oracle Application Development Framework af:table af:commandButton text=Delete actionListener={mybean.performDelete} Example 10–4 shows an actions method, performDelete, which iterates through all the selected rows and calls the markForDeletion method on each one. Example 10–4 Using the rowKey Object public void performDeleteActionEvent action { UIXTable table = getTable; Iterator selection = table.getSelectedRowKeys.iterator; Object oldKey = table.getRowKey; whileselection.hasNext { Object rowKey = selection.next; table.setRowKeyrowKey; MyRowImpl row = MyRowImpl table.getRowData; custom method exposed on an implementation of Row interface. row.markForDeletion; } restore the old key: table.setRowKeyoldKey; } Binding methods for access to the table. public void setTableUIXTable table { _table = table; } public UIXTable getTable { return _table; } private UIXTable _table; 10.2.9 What You May Need to Know About Dynamically Determining Values for Selection Components in Tables There may be a case when you want to use a selectOne component in a table, but you need each row to display different choices in a component. Therefore, you need to dynamically determine the list of items at runtime. While you may think you should use a forEach component to stamp out the individual items, this will not work because forEach does not work with the CollectionModel instance. It also cannot be bound to EL expressions that use component-managed EL variables, as those used in the table. The forEach component performs its functions in the JSF tag execution step while the table performs in the following component encoding step. Therefore, the forEach component will execute before the table is ready and will not perform its iteration function. In the case of a selectOne component, the direct child must be the items component. While you could bind the items component directly to the row variable for example, f:items value={row.Items}, doing so would not allow any changes to the underlying model. Instead, you should create a managed bean that creates a list of items, as shown in Example 10–5 . Example 10–5 Managed Bean Returns a List of Items public ListSelectItem getItems { Grab the list of items Using Tables and Trees 10-27 FacesContext context = FacesContext.getCurrentInstance; Object rowItemObj = context.getApplication.evaluateExpressionGet context, {row.items}, Object.class; if rowItemObj == null return null; Convert the model objects into items ListSomeModelObject list = ListSomeModelObject rowItemObj; ListSelectItem items = new ArrayListSelectItemlist.size; for SomeModelObject entry : list { items.addnew SelectItementry.getValue, entry.getLabel;public } Return the items return items; } You can then access the list from the one component on the page, as shown in Example 10–6 . Example 10–6 Accessing the Items from a JSF Page af:table var=row af:column af:selectOneChoice value={row.myValue} f:Items value={page_backing.Items} af:selectOneChoice af:column af:table

10.2.10 What You May Need to Know About Using the Iterator Tag

When you do not want to use a table, but still need the same stamping capabilities, you can use the iterator tag. For example, say you want to display a list of periodic table elements, and for each element, you want to display the name, atomic number, symbol, and group. You can use the iterator tag as shown in Example 10–7 . Example 10–7 Using the Iterator Tag af:iterator var=row first=3 rows=3 varStatus=stat value={periodicTable.tableData} af:outputText value={stat.count}.Index:{stat.index} of {stat.model.rowCount} af:inputText label=Element Name value={row.name} af:inputText label=Atomic Number value={row.number} af:inputText label=Symbol value={row.symbol} af:inputText label=Group value={row.group} af:iterator Each child is stamped as many times as necessary. Iteration starts at the index specified by the first attribute for as many indexes specified by the row attribute. If the row attribute is set to 0, then the iteration continues until there are no more elements in the underlying data.

10.3 Adding Hidden Capabilities to a Table

You can use the detailStamp facet in a table to include data that can be displayed or hidden. When you add a component to this facet, the table displays an additional column with a toggle icon. When the user clicks the icon, the component added to the