Solution 1:
In your action class which is called before displaying the page with the
drop down box,
use a business delegate to access your data from the appropriate data source
into some
type of collection. Store the collection in the appropriate scope (session,
request).
Have the page render the collection using a custom tag (either JSTL, Struts,
user-defined)

Solution 2:
If your data is static, then you want to use a business delegate to access
your data
from the appropriate data source into some type of collection, and place the
collection
in the ServletContext. There it will be available to your entire application
and you
will only need to hit the database once.

This can be done in several ways:
 -ServletContextListener
 -Servlet (programmed to load on application start up)
 -Struts Plug-in
 -Static data member in a business delegate (lazy loading)

Then, as in Solution 1, have the page render the collection using
a custom tag (either JSTL, Struts, user-defined).


Let me know if you need more detail.

robert


> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:tbachta@;kcp.com]
> Sent: Friday, November 08, 2002 8:50 AM
> To: Struts Users Mailing List
> Subject: Re: select and option tag issues
>
>
>
> I posted this question a couple of days ago and received an answer.
> Unfortunately the answer does not work for me.  The problem I am having is
> on the initial page of my web application I have drop-down boxes that I
> want to be populated with information from a database.  I have no problem
> getting the recordset but do not know how to transfer that recordset data
> into the drop-downs.  I was able to populate the drop-downs similar to the
> example used in the documentation but that does not have  an
> example of how
> to populate them with live data.  Can anyone give me a quick lesson on how
> to do this.
> Tim Bachta
> Information Technology
> MC 48
> 816-997-7137
>
>
>
>
>                       Eddie Bush
>
>                       <[EMAIL PROTECTED]        To:       Struts
> Users Mailing List <[EMAIL PROTECTED]>
>                       t>                       cc:
>
>                                                Subject:  Re:
> select and option tag issues
>                       11/06/2002 11:52
>
>                       AM
>
>                       Please respond to
>
>                       "Struts Users
>
>                       Mailing List"
>
>
>
>
>
>
>
>
>
> Have you discovered the collection attribute of the options tag?  Your
> action can build any collection you desire (ie from a database -- see
> org.apache.struts.util.LabelValueBean for holding the name/value pairs).
>  It then places that collection into some scope (whichever you like) and
> forwards to the page.  Now, by specifying the key you used when placing
> the collection into scope as the value to the collection attribute of
> the options tag, you've got a dynamic drop-down populated from the
> database.
>
> ------------- in your Action subclass
>
> Collection c = ...;
>
> while (...)
> {
>     String label = ...;
>     String value = ...;
>     c.add(new LabelValueBean(label, value));
> }
>
> request.setAttribute("myCollection", c);
>
> ------------- in your JSP
>
> <html:select ... >
>     <html:options collection="c" ... />
> </html:select>
>
> (This isn't in the FAQ, is it?  <goes-to-check/>)
>
> [EMAIL PROTECTED] wrote:
>
> >Hi all,
> >
> >I am very new to struts and I am trying to create combo boxes using the
> ><html:select><html:options> tags.  I have been able to create
> and populate
> >them with string arrays placed on the JSP page similar to the examples in
> >the documentation.  What I really need to do is populate them based on
> >information in a database.  I can create the recordset but after
> that I am
> >lost.  Can anyone please help.  Thank you.
> >Tim Bachta
> >
> >Tim Bachta
> >
>
> --
> Eddie Bush
>
>
>
>
>
> --
> To unsubscribe, e-mail:   <
> mailto:struts-user-unsubscribe@;jakarta.apache.org>
> For additional commands, e-mail: <
> mailto:struts-user-help@;jakarta.apache.org>
>
>
>
>
>
>
>
> --
> To unsubscribe, e-mail:
<mailto:struts-user-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail:
<mailto:struts-user-help@;jakarta.apache.org>


--
To unsubscribe, e-mail:   <mailto:struts-user-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-user-help@;jakarta.apache.org>

Reply via email to