File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes Help regarding the enabling of a button in an xhtml based on the value selected in a selectOneMenu Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Help regarding the enabling of a button in an xhtml based on the value selected in a selectOneMenu" Watch "Help regarding the enabling of a button in an xhtml based on the value selected in a selectOneMenu" New topic
Author

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

Vikram Negi
Greenhorn

Joined: Apr 19, 2011
Posts: 1
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

Joined: Apr 12, 2011
Posts: 200

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

Joined: Dec 25, 2010
Posts: 90

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


When a dream is ending because to come true - OCPJP 6,7. OCE JPA EE6. MCTS
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help regarding the enabling of a button in an xhtml based on the value selected in a selectOneMenu