You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Rajat Pandit <ra...@centergroupinc.com> on 2003/10/20 21:14:50 UTC

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 | rajatp@centergroupinc.com
+91 612 3117606
[ Developer and Part Time Human Being]


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


Re: Help with form bean [urgent]

Posted by Andy Engle <an...@andyengle.com>.
Oops!  Message intended only for Rajat!  Oh well -- hopefully one of us
will be able to help him with the problem he's having.

Have a great day.


Andy

--- Andy Engle <an...@andyengle.com> wrote:
> You wrote:
> 
> > 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,
> 
> Greetings.  Just curious, what is your project for?  Are you doing
> work
> for Motorola?
> 
> Take it easy!
> 
> 
> Andy
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 


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


Re: Help with form bean [urgent]

Posted by Andy Engle <an...@andyengle.com>.
You wrote:

> 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,

Greetings.  Just curious, what is your project for?  Are you doing work
for Motorola?

Take it easy!


Andy


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


RE: Help with form bean [urgent]

Posted by Steve Raeburn <sr...@apache.org>.
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:rajatp@centergroupinc.com]
> 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 | rajatp@centergroupinc.com
> +91 612 3117606
> [ Developer and Part Time Human Being]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
>



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