You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by tb...@kcp.com on 2002/11/06 17:35:21 UTC

select and option tag issues

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




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: select and option tag issues

Posted by Eddie Bush <ek...@swbell.net>.
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/>)

tbachta@kcp.com 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:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: select and option tag issues

Posted by Eddie Bush <ek...@swbell.net>.
If you examine the struts-example.war you will find a JSP named 
'subscription.jsp'.  If you need additional guidance, I'd suggest 
examining that page.  While I don't particularly care for the way it 
makes the collection available, it should serve as a good example of how 
to use html:options.  Be sure to check the javadoc too!

tbachta@kcp.com 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:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>