Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Question on dynamic dropdown list  RSS feed

 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Change your code as follows:

 
Liangfeng Ren
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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
Bartender
Posts: 18709
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!