该表单应如下所示:<h:form> <h:selectOneMenu valueChangeListener="#{bean.valueChanged}" onchange="submit()"> <f:selectItem itemValue="1" itemLabel="First" /> <f:selectItem itemValue="2" itemLabel="Second" /> </h:selectOneMenu></h:form>并且托管bean中的valueChangeListener方法将是:public void valueChanged(ValueChangeEvent event) { //do your stuff}I have the following drop down list:<h:selectOneMenu value="#{user.favCoffee3}" onclick=""> <f:selectItems value="#{user.favCoffee3Value}" var="c" itemLabel="#{c.coffeeLabel}" itemValue="#{c.coffeeValue}" /></h:selectOneMenu>I would like to launch some method from the bean by drop down list item click. How can I achieve it? 解决方案 You can use the valueChangeListener attribute, pointing to a method in the managed-bean and add a submit() in the onchange attribute.The form should look like :<h:form> <h:selectOneMenu valueChangeListener="#{bean.valueChanged}" onchange="submit()"> <f:selectItem itemValue="1" itemLabel="First" /> <f:selectItem itemValue="2" itemLabel="Second" /> </h:selectOneMenu></h:form>And the valueChangeListener method in the managed bean would be:public void valueChanged(ValueChangeEvent event) { //do your stuff} 这篇关于单击h:selectOneMenu调用动作方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-19 02:47