Barry,
You are unnecessarily creating an extra String object here:
        //Create list (in a loop)
        cityList.add(new String(rs.getString("city")));

instead, just use
        cityList.add(rs.getString("city"));



-Richard

-----Original Message-----
From: Barry Volpe [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, October 22, 2003 2:39 PM
To: Struts Users Mailing List
Cc: [EMAIL PROTECTED]
Subject: Re: DynaForms and java.util.ArrayList" 



Hi Mark,

As per Tim's suggestion I am able to use ForEach
with DynaValidatorForm.

Here is what works:

struts-config.xml:

<form-bean name="locationForm" 
     type="org.apache.struts.validator.DynaValidatorForm" >
  <form-property 
     name="state" 
     type="java.lang.String" 
     initial=""/>  
    <form-property 
     name="city" 
     type="java.lang.String" 
     initial=""/>  
 <form-property 
     name="cities" 
     type="java.util.ArrayList"/>
 </form-bean>


Action:

DynaActionForm eForm = (DynaActionForm)form;


//Create list (in a loop)
cityList.add(new String(rs.getString("city")));

eForm.set("cities",cityList);

request.setAttribute(mapping.getAttribute(), eForm); 

or

request.setAttribute("locationForm", eForm); 


In Jsp creates a drop down menu with cities:

 <html-el:select property="city" size="1">
 <html-el:option value="City">Select-A-City</html-el:option>       
      <c:forEach var="city" items="${locationForm.map.cities}">
      <html-el:option value="${city}">
      <c:out value="${city}"/>
       </html-el:option>
      </c:forEach>
       </html-el:select>    


Looks like the fine point of all of this is:

items="${locationForm.map.cities}">

Barry







----- Original Message ----- 
From: "Mark Lowe" <[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
Sent: Tuesday, October 21, 2003 11:41 AM
Subject: Re: DynaForms and java.util.ArrayList" 


> I'm not sure if the forEach way works with indexed form properties. I
> tried and the html:text tags seems to be a tad oblivious to the fact 
> they were nested in a loop.
> 
> <form-property name="cities" type="java.util.ArrayList" />
> ..
> //also you need to scope to session
> 
> <action path="/process-form" name="myForm" scope="session" ...
> 
> ..
> ArrayList cityList = new ArrayList();
> cityList.add(new CityBean());
> cityList.add(new CityBean());
> 
> theForm.set("cities",cityList);
> 
> //you need this too for an unknown reason 
> request.setAttribute("cities",cityList.toArray());
> 
> ..
> 
> <logic:iterate id="city" name="myForm" property="cities"> <html:text 
> name="city" property="name" /> </logic:iterate>
> 
> ..
> 
> I've helped a few tutorial victims with this and it works for them 
> too.
> 
> If you have it running with the forEach tags (they work with the
> html:text or other form bits) I'd like to know..
> 
> Cheers Mark
> 
> 
> 
> On Tuesday, October 21, 2003, at 06:42 PM, Chen, Gin wrote:
> 
> > Remove initial=""
> > Then in your jsp do:
> > <c:forEach var="blah" items="${myFormBean.map.city}"> <c:out 
> > value="${blah}"/> </c:forEach>
> > -Tim
> >
> > -----Original Message-----
> > From: Barry Volpe [mailto:[EMAIL PROTECTED]
> > Sent: Tuesday, October 21, 2003 1:14 PM
> > To: Struts Users Mailing List
> > Subject: DynaForms and java.util.ArrayList"
> >
> >
> >
> > When I define this in my struts-config:
> >
> > <form-property
> >      name="city"
> >      type="java.util.ArrayList"
> >      initial=""/>
> >
> > I get this error:
> >
> > [ServletException in:/tiles/locationselection.jsp] Exception 
> > creating bean of class
> > org.apache.struts.validator.DynaValidatorForm: {1}'
> >
> >  Can I access "city" using JSTL in my jsp.
> >
> > What should I put in my JSP.
> >
> > What am I missing?
> >
> > Thanks,
> > Barry
> >
> > --------------------------------------------------------------------
> > -
> > 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]
> 
> 
> 
> 


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