Ah.. stupid me =)

So the solution with dynaactionform is:
---
public ActionForward execute(ActionMapping _mapping, ActionForm _form,
HttpServletRequest _request, HttpServletResponse _response) throws
Exception 

{

DynaActionForm dynaForm = (DynaActionForm) _form;

String userId = (String) dynaForm.get("userId");

String[] companies = MyDBTools.getUser(userId).getCompanies();
ArrayList allCompanies = MyDBTools.getAllCompanies();
 
dynaForm.set("selectedCompanies", companies);
_request.setAttribute("allCompanies", allCompanies );

return _mapping.findForward("continue");
}

-----Original Message-----
From: Robert Taylor [mailto:[EMAIL PROTECTED] 
Sent: 9. joulukuuta 2004 17:13
To: Struts Users Mailing List
Subject: RE: Multibox & DynaActionForm

You will need to set the "selectedCompanies" in the ActionForm
so that the <html:multibox .../> can determine which companies
have been selected by comparing the company id against the selected
company id.

If "allCompanies" does not change per user, you may want to place that
in 
the ServletContext on application startup to avoid the database hit
everytime that action is executed.

robert

> -----Original Message-----
> From: Jaakko Rytinki [mailto:[EMAIL PROTECTED]
> Sent: Thursday, December 09, 2004 9:14 AM
> To: Struts Users Mailing List
> Subject: Multibox & DynaActionForm
> 
> 
> How I can prepopulate a form containing a multibox when using
> DynaActionForms? The following code doesn't seem to work - it wont
check
> any checkboxes (why?)
> 
> ---
> Action which prepopulates the form:
> ---
> 
> String[] companies = MyDBTools.getUser(userId).getCompanies();
> ArrayList allCompanies = MyDBTools.getAllCompanies();
> 
> _request.setAttribute("selectedCompanies", companies);
> _request.setAttribute("allCompanies", allCompanies );
> 
> ---
> Form
> ---
> 
> <logic:iterate id="company" name="allCompanies">
>       <html:multibox property="selectedCompanies">
>               <bean:write name="company" property="id"/>
>       </html:multibox> 
>       <bean:write name="company" property="name"/>
>       <br>
> </logic:iterate>
> 
> ---
> Form-bean
> ---
> 
> <form-bean
>       name="forms.myForm"
>       type="org.apache.struts.validator.DynaValidatorForm">
> 
>       <form-property name="selectedCompanies"
> type="java.lang.String[]" />
> </form-bean>
> 
> 
> 
> ---------------------------------------------------------------------
> 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