letsbedecent
asked on
html:select of struts
Hi all,
This is what i am doing in the JSP page,
<html:select property="responsibleUnits Id" multiple="true">
<html:options collection="responsibleUni tOptionsLi st" labelProperty="name" property="responsibleUnitI d"/>
</html:select>
Inside the form i have the following,
private String[] responsibleUnitsId;
public String[] getResponsibleUnitsId() {
return responsibleUnitsId;
}
public void setResponsibleUnitsId(Stri ng[] responsibleUnitsId) {
this.responsibleUnitsId = responsibleUnitsId;
}
In the Action Handler this is what i am doing.... .
int size = request.getParameter("resp onsibleUni tsId").len gth();
System.out.println("XXXXXX XXX Size of responsible Units list is " + size);
responsibleUnitsId=new String[size];
System.arraycopy(mlForm.ge tResponsib leUnitsId( ),0,respon sibleUnits Id,0,size) ;
//responsibleUnitsId = request.getParameterValues ("responsi bleUnitsId ");
java.util.Set responsibleUnits = new HashSet();
for(int i=0;i<size;i++)
{
ResponsibleUnit responsibleUnit=(Responsib leUnit)m3M anager.get Responsibl eUnit(resp onsibleUni tsId[i]);
responsibleUnits.add(respo nsibleUnit );
}
mlForm.setResponsibleUnits (responsib leUnits);
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.
This is what i am doing in the JSP page,
<html:select property="responsibleUnits
<html:options collection="responsibleUni
</html:select>
Inside the form i have the following,
private String[] responsibleUnitsId;
public String[] getResponsibleUnitsId() {
return responsibleUnitsId;
}
public void setResponsibleUnitsId(Stri
this.responsibleUnitsId = responsibleUnitsId;
}
In the Action Handler this is what i am doing.... .
int size = request.getParameter("resp
System.out.println("XXXXXX
responsibleUnitsId=new String[size];
System.arraycopy(mlForm.ge
//responsibleUnitsId = request.getParameterValues
java.util.Set responsibleUnits = new HashSet();
for(int i=0;i<size;i++)
{
ResponsibleUnit responsibleUnit=(Responsib
responsibleUnits.add(respo
}
mlForm.setResponsibleUnits
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.
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.. ??
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.la
So change it to:
int size = request.getParameterValues
or to
int size = rmlForm.getResponsibleUnit