Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ajax support In h:selectOneMenu

Tags:

ajax

jsf

jsf-2

I have to call backend code as soon as one value is selected from drop-down list. I am using JSF 2.0. In JSF 1.2 I did it by using <a4j:support> in <h:selectOneMenu>, but I am not geting how to do it in JSF 2.0.

like image 589
Arvind Avatar asked Dec 22 '22 14:12

Arvind


1 Answers

Use the <f:ajax> tag. It's much similar to the <a4j:support>.

<h:selectOneMenu value="#{bean.selectedItem}">
    <f:selectItems value="#{bean.selectItems}" />
    <f:ajax listener="#{bean.valueChanged}" />
</h:selectOneMenu>

with

public void valueChanged() {
    // ...
}

The <f:ajax> has also an event attribute which already defaults to valueChange when used in <h:selectOneMenu>, so it is been omitted.

like image 135
BalusC Avatar answered Dec 28 '22 07:12

BalusC