• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Where and When to load collections for html:selects

 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am needing to load collections for my html:selects in a form. The problem I am having is when and where to load this collections from the database in order to keep that code out of my JSP.
Just an FYI - I am using the DynaValidatorForm instead of hand coding an ActionForm class if this makes any difference, because I have read in a couple of places that this is where you should do this, but that doesn't make sense to me.
My other thought was to load them as a Bean after you log in, but that would require me putting these in the Session and I don't really want/need them in the session object.
Thanks.
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The approach we have used on our projects is to load frequently/commonly used options lists (e.g. list of US States) into the application context. This is done at startup. Less frequently used options lists are put in the request context. This is done before the action forwards to the JSP.
I don't know much about the DynaActionForm as I've been working with 1.0.x but from what I've read about it, I wouldn't think you'd want to put the collection there even if you could. Besides, the Struts select tag documentation is probably one of the most confusing of the lot and I've found it much easier to use when the options list has been placed in one of the context collections; YMMV.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So you create a Servlet that loads at startup and you use something like:
servlet.getServletContext().setAttribute("states", states);
Is this close?
 
Junilu Lacar
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, you could do that. Or you could subclass ActionServlet and override the initOther() method and do the loading there.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks. I will look into that and see what I can come up with.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe a stupid question...
If I subclass ActionServlet how do I load it at startup.
 
Junilu Lacar
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, but bartenders are allowed 1 a day <ducking and running>
http://jakarta.apache.org/struts/userGuide/configuration.html#dd_config_servlet
set the servlet-class to your subclass
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ohhh, you meant THE ActionServlet. Ok, I get it now.
Thanks.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, I put an ArrayList into the context. Now I am a bit confused on how to access that from the html : options tag. Any tips?
[ October 01, 2003: Message edited by: Gregg Bolinger ]
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nevermind, I figured it out.
 
reply
    Bookmark Topic Watch Topic
  • New Topic