Reputation: 1
I know it is propably not the best practice to make this work without a managed bean... but I'd like to make it work that way :)
<h:selectOneMenu id="SelectMenu}">
<f:selectItem itemValue="1" itemLabel="A"/>
<f:selectItem itemValue="2" itemLabel="B"/>
<f:selectItem itemValue="3" itemLabel="C"/>
</h:selectOneMenu>
<h:commandLink value="click" action='#{someController.action(SelectMenu.itemValue)}' />
I guess ajax could be helpfull, but I never used that.
Many thanks for your help
Upvotes: 0
Views: 823
Reputation: 31679
Bind your <h:selectOneMenu />
value to the view directly:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:form>
<h:selectOneMenu value="#{selected}">
<f:selectItem itemValue="1" itemLabel="A" />
<f:selectItem itemValue="2" itemLabel="B" />
<f:selectItem itemValue="3" itemLabel="C" />
</h:selectOneMenu>
<h:commandLink value="click" action='#{myBean.action(selected)}' />
</h:form>
</html>
@ManagedBean
@RequestScoped
public class MyBean {
public void action(String selectedValue) {
System.out.println("Selected " + selectedValue);
}
}
Upvotes: 1