File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes Question on dynamic dropdown list Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Question on dynamic dropdown list" Watch "Question on dynamic dropdown list" New topic

Question on dynamic dropdown list

Melinda Savoy
Ranch Hand

Joined: Jun 21, 2005
Posts: 386

I have a helper class: AccountType that has a getter and setter for acctTypeID.

I have a bean class where a method called: getFromAccountTypes that accesses a DAO object that queries the database using the following method and populates the acctTypeID property above in the AccountType class.:

In my JSF page I have the following code:

My problem is that the value of the <h:selectOneListbox...> is the acctTypeID + description and I only need the acctTypeID.

If someone could please look at my code to let me know what I'm doing wrong it would be appreciated. Thank you.
Liangfeng Ren

Joined: Jul 28, 2010
Posts: 7

Change your code as follows:

Liangfeng Ren

Joined: Jul 28, 2010
Posts: 7

Have a look at SelectItem API. If you only pass one argument to its construct, both value and label property will be set to that argument. That's reason why the value you got is acctTypeID + description.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15641

Actually, you really shouldn't put that much logic in a "get" method. Because it can be invoked multiple times on a single request, it can have side effects and impact performance.

Usually I either prep the actual returned information in advance (for example, in a PostConstruct method) or cache it:

Customer surveys are for companies who didn't pay proper attention to begin with.
I agree. Here's the link:
subject: Question on dynamic dropdown list
Similar Threads
Help - question on selectOneListbox and page reloads
Using dropDown in jsf
Dymaic SelectOnelist and Onchange event
JSF managed bean question
Argument Error: One or more parameters are null.