I have a table with 2 selectOneMenu components.
I would like that once a record was chosen in the first selectOneMenu component it will update the other selectOneMenu with Ajax in the same row.
My table:
<p:dataTable value="#{myBean.myInfo}" var="myInfo">
<p:column>
<f:facet name="header">Group</f:facet>
<h:selectOneMenu value="#{myInfo.myInfoType.code}">
<f:selectItems value="#{myBean.myList}" />
<f:ajax event="change" execute="@this" listener="#{myBean.refershNames}" render="myNames"/>
</h:selectOneMenu>
</p:column>
<p:column>
<f:facet name="header">Name</f:facet>
<h:selectOneMenu id="myNames" value="#{myInfo.myInfoType.secondCode}">
<f:selectItems value="#{myBean.mySecondList}" />
</h:selectOneMenu>
</p:column>
<p:dataTable>
In the bean I have:
List<SelectItem> myList,mySecondList;
public void refershNames(AjaxBehaviorEvent event){
//how can I retrieve the selected item and update the relevant record?
}
How can I do it with Ajax? I am using JSF2
Wrap the datatable value in
DataModel<E>so that you can obtain themyInfoobject in question byDataModel#getRowData(). So,with
and
Update as per the comments, here is the testcase I created after you told that it didn’t work. It worked for me with Mojarra 2.0.3 on both Tomcat 7.0.5 and Glassfish 3.0.1.
com.example.Itemcom.example.Beantest.xhtmlThis testcase proves that whenever you change a dropdown value in the 1st column, then the dropdown value in the 2nd column in the same row will be reflected to retrieve the same value.