File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Populating Select Options in Struts Application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Populating Select Options in Struts Application" Watch "Populating Select Options in Struts Application" New topic

Populating Select Options in Struts Application

Robert Wiscup
Ranch Hand

Joined: Oct 18, 2009
Posts: 45
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?


Siva Masilamani
Ranch Hand

Joined: Sep 19, 2008
Posts: 385
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.


Failure is not an option.
David Newton

Joined: Sep 29, 2008
Posts: 12617

Which version of Struts? Are you using Spring?
I agree. Here's the link:
subject: Populating Select Options in Struts Application
It's not a secret anymore!