• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic