Put your beans in application scope with the first action called (test to
see if they are already present) and then call their properties with
<html:option><html:iterate> or <html:options> in the JSP.

For example, I have a servlet called State that retrieves a list of all
states and their respective 2-letter codes from the database and sticks them
in a HashMap that I'll call mapStates.  In my first action class I'd do:


if( request.getSession()
    .getServletContext()
    .getAttribute( "states") == null) {
        Map mapStates = new HashMap( State.getMapStates());
        request
        .getSession()
        .getServletContext()
        .setAttribute( "states", mapStates);
}


Now, any user can access the states in the JSP without going to the
database:


<html:select property="state" styleId="state">
<logic:iterate name="<%= application.getAttribute( \"states\") %>"
               property="mapStates"
               type="State"
               id="state">
<html:option value="<%=state.getAbbreviation()%>">
           <%= state.getName() %>
</html:option>
</logic:iterate>
</html:select>


Mark

-----Original Message-----
From: Schneider, Eric [mailto:[EMAIL PROTECTED]]
Sent: Monday, April 22, 2002 2:13 PM
To: 'Struts Users Mailing List'
Subject: RE: Where is it best to populate default form bean collections?


How are other developers initializing
application scope resources?

For example, maybe a list of cities or states.  Things that end up in
numerous forms that don't change often, but are large enough to be stored in
the database.  These kind of things don't seem appropriate in a user's
session.

Thanks,
eric

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to