Link to home
Start Free TrialLog in
Avatar of letsbedecent
letsbedecent

asked on

html:select of struts

Hi all,

This is what i am doing in the JSP page,

<html:select property="responsibleUnitsId" multiple="true">
<html:options collection="responsibleUnitOptionsList" labelProperty="name" property="responsibleUnitId"/>
</html:select>



Inside the form i have the following,

private String[] responsibleUnitsId;

public String[] getResponsibleUnitsId() {
            return responsibleUnitsId;
      }

public void setResponsibleUnitsId(String[] responsibleUnitsId) {
            this.responsibleUnitsId = responsibleUnitsId;
      }


In the Action Handler this is what i am doing.... .

int size = request.getParameter("responsibleUnitsId").length();
System.out.println("XXXXXXXXX  Size of responsible Units list is   " + size);
responsibleUnitsId=new String[size];
System.arraycopy(mlForm.getResponsibleUnitsId(),0,responsibleUnitsId,0,size);
//responsibleUnitsId = request.getParameterValues("responsibleUnitsId");
java.util.Set responsibleUnits = new HashSet();
for(int i=0;i<size;i++)
{
      ResponsibleUnit responsibleUnit=(ResponsibleUnit)m3Manager.getResponsibleUnit(responsibleUnitsId[i]);
      responsibleUnits.add(responsibleUnit);
}
mlForm.setResponsibleUnits(responsibleUnits);

ResponsibleUnits is of type java.util.Set. (FYI)

Now, the problem is the size of the request parameter is always 1, no matter how many units i select on the JSP page.

Any suggestion,

Thanks.
Avatar of aozarov
aozarov

>> int size = request.getParameter("responsibleUnitsId").length();
From the Javadoc:
You should only use this method when you are sure the parameter has only one value. If the parameter might have more than one value, use getParameterValues(java.lang.String).

So change it to:
int size = request.getParameterValues("responsibleUnitsId").length();
or to
int size = rmlForm.getResponsibleUnitsId().length();
Avatar of letsbedecent

ASKER

ooooops, i totally forgot that...

yeah, but why would it complain when i was using only request.getParameter() and was not having corresponding property in the action form

Do we need to have a property in action form for every field in the html form ?? cant we just use request.getParameter() when we dont want a property in the action form for this field.. ??
ASKER CERTIFIED SOLUTION
Avatar of aozarov
aozarov

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial