Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Where and When to load collections for html:selects

 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
Junilu Lacar
Bartender
Pie
Posts: 7758
61
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • 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
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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
Bartender
Pie
Posts: 7758
61
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • 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
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe a stupid question...
If I subclass ActionServlet how do I load it at startup.
 
Junilu Lacar
Bartender
Pie
Posts: 7758
61
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • 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
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ohhh, you meant THE ActionServlet. Ok, I get it now.
Thanks.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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 ]
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nevermind, I figured it out.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic