This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes JSF and the fly likes How to diable a item in select option? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » JSF
Bookmark "How to diable a item in select option? " Watch "How to diable a item in select option? " New topic

How to diable a item in select option?

tej ku

Joined: Mar 13, 2010
Posts: 19
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<jsp:root version="2.0" xmlns:jsp=""

<h:selectOneMenu id="readyToIssue"
value="#{suba na.requiredInd}">
<f:selectItem itemValue="Y" itemLabel="Yes" />
<f:selectItem itemValue="N" itemLabel="No" />
<f:selectItem itemValue="P" itemLabel="Processed" />

There are three status of a field in database. If the database table has "P" state yes and no should be disabled and if "the status is "yes or no" "P" should be disabled.
we are using
Ganesh Podaralla

Joined: Feb 22, 2010
Posts: 23
You can write a method in the backing bean as below

public boolean isItemProcessed()
return true;
return false;

Then in the page,

<f:selectItem itemValue="Y" itemLabel="Yes" itemDisabled="#{!bean.isItemProcessed}"/>
<f:selectItem itemValue="N" itemLabel="No" itemDisabled="#{!bean.isItemProcessed}"/>
<f:selectItem itemValue="P" itemLabel="Processed" itemDisabled="#{bean.isItemProcessed}"/>

If you do not want to write a separate method, you can directly compare the data with itemDisabled="#{ == "P"}" and itemDisabled="#{ != "P"}
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17026

Somebody asked this question about 2-3 months ago. Search this forum and you'll find a detailed discussion about it.

Also, you can make your code and XML more readable if you use the "Code" button on our message editor.

Customer surveys are for companies who didn't pay proper attention to begin with.
tej ku

Joined: Mar 13, 2010
Posts: 19
Hi Ganesh Podaralla,
Thanks for the reply, It is solved.......
I agree. Here's the link:
subject: How to diable a item in select option?
jQuery in Action, 3rd edition