If you've set the Map up in you Action, something like this:
    Map countries = new HashMap();
    countries.put("AF", "Afghanistan");
    countries.put("AL", "Albania");
    countries.put("DZ", "Algeria");
    countries.put("AS", "American Samoa");
    countries.put("AD", "Andorra");
    countries.put("AO", "Angola");
    countries.put("AI", "Anguilla");
    countries.put("AQ", "Antarctica");
    request.setAttribute("countries", countries);

You can generate the list in your JSP using:
  <html:select property="countryId">
        <html:options collection="countries" property="key" labelProperty="value"
/>
  </html:select>

'countryId' is the name of the property in your ActionForm
'countries' is the request scope attribute name where you stored the Map.

You would probably want to load the list from a properties file or database
and since these values don't change very often, you could do this once at
startup and place the Map in application scope rather than in the request.

To generate checkboxes, use something like this:

  <logic:iterate name="countries" id="country">
    <html:multibox property="countryIds" name="countries">
      <bean:write name="country" property="key"/>
    </html:multibox>
    <bean:write name="country" property="value"/><br/>
  </logic:iterate>

Your form property must be a String array to receive multiple values.

Steve

p.s. Please don't put 'urgent' in your subject line. It may not achieve the
effects you desire ;-)


> -----Original Message-----
> From: Rajat Pandit [mailto:[EMAIL PROTECTED]
> Sent: October 20, 2003 12:15 PM
> To: 'Struts Users Mailing List'
> Subject: Help with form bean [urgent]
>
>
> Ok, yet another attempt to explain my problem. Say I have a registration
> form and I have the list of countries stored in an ArrayList with each
> element as a key, value pair (Map). Now when I call the registration
> form. The actionForm for the the registration form has one field country
> (with both the getter and setter). How do I write the bean tag, so that
> the ArrayList (which is placed in the request scope already) is taken to
> render a dropdown menu of countries and the value of the selected item
> goes into the countryId property of the registration ActionForm.
>
> If ur still with me so far, then yet another question, how do do the
> same in case I want to user to select the countries from a checkbox
> (could be possibly multiple countries) if possible please give me a
> sample code to learn as well.
>
> My project deadline is coming close and I am stuck with conceptual
> problems. Please consider this as urgent call for help.
>
> Thanks in advance.
>
>
>
>
> Rajat Pandit | [EMAIL PROTECTED]
> +91 612 3117606
> [ Developer and Part Time Human Being]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>



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

Reply via email to