• Post Reply Bookmark Topic Watch Topic
  • New Topic

Dropdown i created, has a list of items. I feel there is some mistake with the Bean.

 
Sivarama Raju
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried a lot with the Dropdown, but couldn't give action to the submit button, for the items in dropdown. This is my code:

JSF:
<h:selectOneMenu value="#{CalcBean.selectValue}">
<f:selectItem itemLabel="Add" itemValue="SubmitAdd" />
<f:selectItem itemLabel="Multiply"itemValue="SubmitMultiply" />
<f:selectItem itemLabel="Subtract" itemValue="SubmitDivide" />
<f:selectItem itemLabel="Divide" itemValue="SubmitDivide"/>
</h:selectOneMenu>

<h:commandButton action="#{CalcBean.selectChoice}" "Submit"></h:commandButton>

Backing bean:

public String selectChoice() {
String returnVal = "";
if (selectValue == "SubmitAdd") {
returnVal = add();
} else if (selectValue == "SubmitMultiply") {
returnVal = multiply();
} else if (selectValue == "SubmitSutract") {
returnVal = subtract();
} else if (selectValue == "SubmitDivide") {
returnVal = divide();
}
return returnVal;
}


public String getSelectChoice() {
return selectChoice;
}

public void setSelectValue(String aSelectValue) {
this.selectValue = aSelectValue;
}

public String getSelectValue() {
return selectValue;
}


Hey i am new friends, might have done some silly mistakes.

Thanks and regards,
siva
 
Venkat Sadasivam
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cannot call action method through javascript.

Fetch the dropdown value in your action method perform required operation as you wish.

If you want to trigger an action in onchange of dropdown, here is the work around.

<h:selectOneMenu value="#{CalcBean.selectValue}" onchange="document.getElementById('button').click()">

<h:commandButton action="#{CalcBean.selectChoice}" value="Submit" id="button"></h:commandButton>
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!