Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help regarding the enabling of a button in an xhtml based on the value selected in a selectOneMenu

 
Vikram Negi
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am using selectOneMenu in my xhtml and i need to enable or disable a button based on the change of the value in the drop down.
Below is my code
<tbody>
<tr>
<td>
<h:selectOneMenu id="selectPatient"
value="#{valueManager.selectedValue}">
<f:selectItems value="#{valueManager.valueList}"
itemLabel="#{valueManager.valueList}"/>
</h:selectOneMenu>
</td>
<td>
<a4j:commandButton id="generateCCD" value="#{messages.generate}"
action="#{valueManager.calculate}">
</a4j:commandButton>
</td>
</tr>
</tbody>

valueManageris my object with a variable (selectedValue) and a list (valueList) as the properties of the object.

The values of the list are displayed in the selectOneMenu, with the first value (i.e. the default selected value) as blank.
Now i also using a command button which, when clicked, calls a function (calculate) from the object.

But I need to disable or enable the button based on the value selected in the selectOneMenu i.e. the button remains disabled if the blank value is selected, but it is enabled if any other value is selected. I need to use javascript for this.

Please help me.
Thanks.
 
Guy deLyonesse
Ranch Hand
Posts: 200
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you need to use JavaScript?

With JSF you can use rendered="#{backingBean.buttonEnabled}" or enabled="#{backingBean.buttonEnabled}" and use your bean to set "true" or "false" for that value based on tyhe selection from the menu.
 
Cesar Loachamin
Ranch Hand
Posts: 90
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vikram

You don't need use javascript, you can use the EL to solve your problem, for example:

You need submit the form when you select a item in the selectOneMenu using the onchange event, and using the disabled attribute of the commandButton
I hope this help you with you problem
Regards
Cesar
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic