• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Populating Select Options in Struts Application

 
Robert Wiscup
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I was wondering where I should execute code to populate my dropdown boxes from my database in my Struts application? I guess I want to do this once and populate the bean and put in the appropriate scope.

Can someone share the best place to do this?

Thanks,

Rob
 
Siva Masilamani
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can do that if the number of datas in the list is less and list is constant(will change very rarely).E.g state name etc

What i would do is create a model class and create a static HashMap and store each list into the map.

E.g i would store list of states into ArrayList and then store that array list into hasp map under the key "StateList"

Similarly you can store other list that gonna stay constant int he database.This could avoid hitting database everytime.

But everytime you want to display the list, you have to check the Array list from the haspmap and if it is empty then go to database and retrieve the data and store it inthe hash map and then return the list from the hashmap.

Then you can put the list in the appropriate scope and forward to the requires pages.

This is my suggesstion only.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which version of Struts? Are you using Spring?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic