Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setPropertyActionListener with h:selectOneMenu

Tags:

jsf

primefaces

I am using a datatable with two columns which will have a label and a 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 the option for setting the value with the help of f:setPropertyActionListener. I am just wondering how to set the value while I am 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>
like image 962
Real Chembil Avatar asked Jan 20 '26 21:01

Real Chembil


1 Answers

you can use the change ajax event.

When some item will be change in your selectOneMenu the ajax call some method in you Bean.

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 the value of fieldValue or pass with parameter to another Bean method in you xhtml.

like image 98
Tiago Vieira Dos Santos Avatar answered Jan 22 '26 13:01

Tiago Vieira Dos Santos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!