getting  arraylist/array  values in action class

Posted on 2006-05-18
Last Modified: 2007-12-19
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">

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

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[]"/>

any help greatly appreciated

Question by:jaggernat
    LVL 11

    Accepted Solution

    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.
    LVL 10

    Author Comment

    ok , so what do i do in my action class to get the array values ?

    do i impliment the method populate(form, request);
    LVL 11

    Expert Comment

    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);
    LVL 10

    Author Comment

    >>>>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");


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    In the modern office, employees tend to move around the workplace a lot more freely. Conferences, collaborative groups, flexible seating and working from home require a new level of mobility. Technology has not only changed the behavior and the expe…
    This paper addresses the security of Sennheiser DECT Contact Center and Office (CC&O) headsets. It describes the DECT security chain comprised of “Pairing”, “Per Call Authentication” and “Encryption”, which are all part of the standard DECT protocol.
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now