You might do better asking Struts questions on the Struts user mailing list
([EMAIL PROTECTED] to subscribe).
Gaurav Gehlot wrote:
> Hi,
> Thanx for reply, but I want to do it using the select custom tag in the
> struts framework.
>
> -gg
> -----Original Message-----
> From: A mailing list about Java Server Pages specification and reference
> [mailto:[EMAIL PROTECTED]]On Behalf Of Stefan Bushev
> Sent: Wednesday, September 27, 2000 2:43 AM
> To: [EMAIL PROTECTED]
> Subject: Re: Select tag in Struts
>
> ok, lets guess, that you have an array for abbrevs and array for names:
>
> so ..
> <% myAbbrevs[0] = "AZ";
> myAbbrevs[1] = "CA";
> ...
>
> myStates[0] = "Arizona";
> myStates[1] = "California";
> ...
> %>
> ...
> <select name="states">
> <option value="<%=myAbbrevs[0] %>"><%=myStates[0] %></option>
> <option value="<%=myAbbrevs[1] %>"><%=myStates[1] %></option>
> ...
> </select>
>
Given the two arrays listed above, check out the <struts:options> tag to generate
all of the options and their corresponding descriptions:
<%
// These would normally be created in an Action, not scriptlets
// but are placed here to have all the relevant stuff together
String stateAbbrs[] = new String[] {"AZ", "CA", ... };
pageContext.setAttribute("stateAbbrs", stateAbbrs);
String stateNames[] = new String[] {"Arizona", "California", ... };
pageContext.setAttribute("stateNames", stateNames);
%>
<struts:select name="states">
<struts:options name="stateAbbrs" labelName="stateNames"/>
</struts:select>
You can mix <struts:option> and <struts:options> elements inside the select tag.
For example, to create a dummy "Select A State" option at the top of the list, do
this instead:
<struts:select name="states">
<struts:option value="--">Select A State</struts:option>
<struts:options name="stateAbbrs" labelName="stateNames"/>
</struts:select>
The Struts example app uses this approach on the "subscription.jsp" page.
>
> hope that will help
>
> s.b.
>
Craig McClanahan
====================
See you at ApacheCon Europe <http://www.apachecon.com>!
Session VS01 (23-Oct 13h00-17h00): Sun Technical Briefing
Session T06 (24-Oct 14h00-15h00): Migrating Apache JServ
Applications to Tomcat
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets