Another suggestion is to use the DependencyFilter in Java Web Parts:
http://javawebparts.sourceforge.net/javadocs/javawebparts/filter/DependencyFilter.html
(I seem to be offering this suggestion a lot lately!)
With the DependencyFilter, you could define in an XML file what is
essentially a "managed" object to be created and stuffed into session.
You can do a bunch of different initializations with the object,
including calling methods on it or passing it off to another object to
initialize, either of which would probably fit your requirements well
because you can do whatever you need to at that point.
You *could* even create an ActionForm using this filter and populate it
accordingly. In fact, there is some details on doing that out on the
Wiki now:
http://wiki.apache.org/struts/PreInitializeActionForm
I don't know if doing the ActionForm is the best answer, but it should
work just the same.
I'm not sure how you could handle the error situations though... the
only suggestion that comes to mind is to have a check downstream from
this filter (either another filter or the first Action that executes as
part of your application), and if the object isn't in session and
initialized properly, then redirect to the logon page, or otherwise
appropriately handle it.
Frank
Wendy Smoak wrote:
From: "Rob Turknett" <[EMAIL PROTECTED]>
I want to populate a select element with items from a database. The items
can be retrieved by making calls to an API that retrieves data from the
database. These API methods may throw exceptions if the database is
inaccessible, or if the user is not logged in. The items only need to be
retrieved once per session, and should therefore be cached in the user's
session.
What is the best way to do this in Struts? Where should I make the
calls to
retrieve the list items? If I do this in the ActionForm, I am not sure
what
to do if an exception is thrown (for instance, if the user is not
logged in,
how to forward to the login page).
I have the same requirements. I use a combination of a Filter to check
whether the user is logged in, and a Session Listener to retrieve the
items and put them in session scope. (Neither of these is dependent on
Struts.)
http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/Filter.html
http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/http/HttpSessionListener.html
--
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]