In my struts jsp page, I have a form.  It's corresponding formbean is in 
the request via my action class.  My formbean has a property of type 
collection that I would like to use to populate a select box.  I have done 
it a couple of ways, but it's real messy.

Does anybody have a more elegant solution?  Both ways below work.  but ugh!

Thanks!

<%
   //get the formbean out of request
   com.healthgauge.UserForm uf = 
(com.healthgauge.UserForm)request.getAttribute("userForm");     
   //get the collection and stuff in pageContext
   pageContext.setAttribute("companies",uf.getCompanies());
%>
       <html:select property="companyId">
         <html:options collection="companies" property="id"
                    labelProperty="companyName"/>
       </html:select>
vs.
       <html:select property="companyId">
<logic:iterate id="company" name="userForm" property="companies">
<option value="<bean:write name="company" property="id" filter="true"/>">
<bean:write name="company" property="companyName" filter="true"/>
</logic:iterate>
       </html:select>

Reply via email to