First of all, you cannot do this without using a managed bean.
The best approach would be to use DataModelas valuefor h:dataTable, so that you can get the currently selected String object DataModel#getRowData(). You only need to make sure that the bean saves the same model in a subsequent request. In other words, fill in the model in the bean constructor.
<h:form>
<h:dataTable value="#{bean.model}" var="item">
<h:column>
<h:commandButton value="View Object" action="#{bean.view}"/>
</h:column>
</h:dataTable>
</h:form>
( ) bean, :
public class Bean {
private DataModel model;
private Item item;
public Bean() {
List<Item> list = new ArrayList<Item>();
list.add(new Item(1, "value1"));
list.add(new Item(2, "value2"));
list.add(new Item(3, "value3"));
model = new ListDataModel(list);
}
public String view() {
item = (Item) model.getRowData();
return "view";
}
public DataModel getModel() {
return model;
}
public Item getItem() {
return item;
}
}
, JSF 1.x, 2.x, @ViewScoped bean .
:
<p>