I have a datatable where the rows are dynamic and each row contain a selectOneMenu. If I have a button on each row and I want to get the selected item on the
Wrap the collection behind datatable's value in a DataModel
private List- items;
private DataModel
- model; // +getter
@PostConstruct
public void init() {
this.items = loadItSomehow();
this.model = new ListDataModel
- (items);
}
(the Item in this example is just the javabean class representing every row, e.g. Person, Product, etc)
Bind it to the datatable's value instead.
If the dropdown is bound to a property of Item and the button to a method of the same bean ...
... then you can grab the current item by DataModel#getRowData() and corrspondingly also the selected value in action method as follows:
public void submit() {
Item item = model.getRowData();
String value = item.getValue();
// ...
}