getting arraylist/array values in action class

Dear experts

I am using Dynavalidatorform. and in  my jsp i have a field
 <html:select property="abbtlFacs" styleClass="formstyle" tabindex="18" multiple="multiple" size="8" style="width:300px">
 </html:select>

the above field has single/multiple values. Now in the action class i am trying to get
the values of the above field like this



DynaValidatorForm f = (DynaValidatorForm) form;
String abbtlFacs = (String)f.get("abbtlFacs");

and i am getting the single string value.

but when the above field has multiple values ,
i want to get all those values in my action class, but i dont know how i should proceed.
Do i need to put it in an array.

do i use optionscollection like

<html:select property="abbtlFacs" styleClass="formstyle" tabindex="18" multiple="multiple" size="8" style="width:300px">
 <html:optionsCollection property="allvalues" value="value" label="label"/>
  </html:select>

and define "allvalues"  as an array in my dyna form in struts config like this
<form-bean name="DynaForm" type="org.apache.struts.validator.DynaValidatorForm" dynamic="true">
           <form-property name="abbtlFacs" type="java.lang.String"/>

           <!--fields for logentry report-->
          <form-property name="allvalues" type="java.lang.String[]"/>
</form-bean>



any help greatly appreciated

thanks
J
LVL 10
jaggernatAsked:
Who is Participating?
 
fargoCommented:
in the action class, doing
org.apache.struts.util.RequestUtils.populate(form, request);

will fill the form with request parameters. Only thing u need to do is to have String[] property [to handle multiple values] for your select list.
0
 
jaggernatAuthor Commented:
ok , so what do i do in my action class to get the array values ?

do i impliment the method populate(form, request);
0
 
fargoCommented:
No, it is already available in RequestUtils class of struts.

instead of form below, use your defined form.
org.apache.struts.util.RequestUtils.populate(form, request);
0
 
jaggernatAuthor Commented:
>>>>instead of form below, use your defined form

which form below?

ok, if this is my action class with this method getValues, how do i use RequestUtils class to get the values which user
selected in the <html:select>

public ActionForward getValues(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
{
DynaValidatorForm f = (DynaValidatorForm) form;

// org.apache.struts.util.RequestUtils.populate(form, request);

return mapping.findForward("success");
}

thanks,
J
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.