SetPropertyActionListener with h: selectOneMenu

I am using a datatable with two columns that will have a label and selectOneMenu.

I need to display the selectOneMenu list dynamically, for which I need to set the level id here in the bean. In commandbutton / commandLink, we have an option to set the value using the f: setPropertyActionListener function. I'm just wondering how to set the value while I'm using selectonemenu. Any help would be appreciated.

    <p:dataTable style="width:750px;" id="inResultTable" var="result"
    value="#{RequestBean.independentFields}">
    <p:column>
    <f:facet name="header">
    <h:outputText value=" " />
    </f:facet>
    <h:outputText value="#{result.field_label}" />
    </p:column>
    <p:column>
    <f:facet name="header">
    <h:outputText value="" />
     </f:facet>
    <ui:repeat value="#{RequestBean.independentFields}" var="itm">   
    <h:selectOneMenu value="#{RequestBean.field1Value}"
     rendered="#{result.level_id==itm.level_id}">
    <f:selectItems value="#{RequestBean.indField}" />
    </h:selectOneMenu>
    <f:setPropertyActionListener target="#{RequestBean.level_id}"
     value="#{itm.level_id}"></f:setPropertyActionListener>
     </ui:repeat>
     </p:column>
     </p:dataTable>

      

+3


source to share


1 answer


you can use change ajax event.

When any element is changed in your selectOneMenu, the ajax call will call some Bean method on you.

Like this:



<h:selectOneMenu value="#{RequestBean.field1Value}"
     rendered="#{result.level_id==itm.level_id}">
    <f:selectItems value="#{RequestBean.indField}" />
    <f:ajax event="change" listener="#{yourBean.yourMethodToChangeSomeValue}" />
</h:selectOneMenu>

      

and in your method you can use fieldValue or pass another Bean method in xhtml with parameter.

+1


source







All Articles