aspose file tools
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 RabbitMQ in Depth this week in the Open Source 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: 387

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: 16725

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