JEE

Access Rendered Datatable Row In Bean

Initial attempt

Bind the datatable to a UIData attribute in your backing bean:

<t:dataTable id="someTable"
	...
	value="#{yourBackingBean.list}"
	binding="#{yourBackingBean.someTable}">
	...
	<t:column>
		<f:facet name="header" />
       		<h:outputText value="#{yourBackingBean.someValue}" />
	</t:column>
	...

In your backing bean, query the UIData attribute for the current row.

class YourBackingBean {
	private UIData someTable;
	public void setSomeTable(UIData someTable) {
		this.someTable = someTable;
	}
	public UIData getSomeTable() {
		return someTable;
	}

	public List<YourRowData> getList() {
		...
	}

	public String getSomeValue() {
		final YourRowData row = (YourRowData) someTable.getRowData();
		...
	}
}

Problems with session-scoped backing beans

If your backing bean is session-scoped, you may get problems with JSF ID generation. I recognized this when I was working in a Spring application, accessing a datatable row as described above and loading the page twice. I worked around this by creating a second, request-scoped bean which I access from the Facelet/JSP instead. This bean gets the model, i.e. the YourBackingBean instance, injected by Spring so that I can query its data from there.

Knowledge Base

Game Development

Personal

PmWiki

pmwiki.org

edit SideBar

Page last modified on July 10, 2008, at 08:58 PM