Reputation: 93
I have a dataTable which one of the columns contains a selectOneMenu (a.k.a dropDownList). Basically each row has a selectOneMenu which has a list of values. Is there a posibility to pass the row data or key whenever the selectOneMenu value has been selected? This way I can loop through my list of objects, allocate that specific object of the row and change the value This is not my code but a simple example:
<p:column headerText="Year">
<h:outputText value="#{car.year}" />
</p:column>
<p:column headerText="Brand">
<h:outputText value="#{car.brand}" />
</p:column>
<p:column headerText="SelectOne">
<p:selectOneMenu value="#{dtBasicView.selectedValue}">
<f:selectItem itemLabel="#{dtBasicView.listOfValues}" />
<f:selectItems value="#{dtBasicView.listOfValues}"/>
</p:selectOneMenu></p:column>
</p:dataTable>
Upvotes: 0
Views: 4329
Reputation: 1108742
This way I can loop through my list of objects, allocate that specific object of the row and change the value
That effort is unnecessary. Just bind input component's value directly to the desired property.
<p:selectOneMenu value="#{car.selectedValue}">
This way JSF will transparently do all that effort for you.
If you intend to listen on the value change event so that you can do any additional actions, nest a <p:ajax listener="#{bean.listener}">
inside the input component. You can even pass the current row object to the listener method.
<p:selectOneMenu ...>
...
<p:ajax listener="#{bean.changeSelectedValue(car)}" />
</p:selectOneMenu>
public void changeSelectedValue(Car car) {
// ...
}
Upvotes: 3