html:select of struts

Posted on 2005-04-15
Medium Priority
Last Modified: 2012-05-05
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"/>

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];
//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 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,

Question by:letsbedecent
  • 2
LVL 15

Expert Comment

ID: 13792272
>> 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();

Author Comment

ID: 13792322
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.. ??
LVL 15

Accepted Solution

aozarov earned 2000 total points
ID: 13792357
>> Do we need to have a property in action form for every field in the html form ??
No, that is only a conveient way to access request data which is supported by struts.

>> cant we just use request.getParameter() when we dont want a property in the action
Sure, you can though probably you want to always use the plural style (and in some cases to get an array of one item).

>> but why would it complain when i was using only request.getParameter()
this returns a string. A string has a method length();

>> my previous example: int size = request.getParameterValues("responsibleUnitsId").length();
It is actually should be int size = request.getParameterValues("responsibleUnitsId").length; // after all it returns an array

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Suggested Courses
Course of the Month9 days, 7 hours left to enroll

621 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