I'm doing a project on jsf and i'm using a select one menu that allows the user to choose an item and them press submit. When the button is clicked the jsf call the bean and it should receive the value selected but i always get a empty result. I saw other post and i guess i'm pretty close of others answers, i guess it just a small detail that is missing
Here is my code:
<h:selectOneMenu id="sel1" value="#{foo.bankName}">
<f:selectItems value="#{foo.bankNameMap}" />
</h:selectOneMenu>
<h:commandButton id="validate" value="Submit"
action="#{foo.submit}"/>
And now on bean:
public String getBankName() {
return bankName;
}
public void setBankName(String bankName) {
this.bankName = bankName;
}
private static Map<String,Object> bankNameMap;
public Map<String,Object> getBankNameMap() {
return bankNameMap;
}
@PostConstruct
public void init() {
initiateDropDown();
}
public void initiateDropDown() {
bankNameMap = new LinkedHashMap<String,Object>();
bankNameMap.put("aaaa" , "aaaa");
}
public void submit(){ //method called when clicked on the button
System.out.println("item " +bankName);
}
output:
item
Thanks in advance