This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Struts and the fly likes How to populate ActionForm class for html:select mutiple= Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to populate ActionForm class for html:select mutiple="true" values?" Watch "How to populate ActionForm class for html:select mutiple="true" values?" New topic
Author

How to populate ActionForm class for html:select mutiple="true" values?

Kamlesh Dhawale
Greenhorn

Joined: Aug 15, 2002
Posts: 8
I need help in getting values of a <html:select mutiple="true"> tag. The tag is set to select multiple options. What method should I write in the ActionForm class to capture all the selected values.
Thanks,
Kamlesh


Kamlesh Dhawale,<p>IBM XML, SCJP2
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4458
    
    6

The form property should be a String array with its corresponding getter/setter. Only selected items will be in the array. In the form's reset method, you need to clear the array (I use a reference to static final zero-sized array to initialize mine).

E.g.
private static final String[] RESET_ARRAY = new String[0];
String[] multiOpt;
public .. reset() {
  ...
  multiOpt = RESET_ARRAY;
  ...
}

public String[] getMultiOpt() {
  return multiOpt;
}

public void setMultiOpt(String[] selectedValues) {
  multiOpt = selectedValues;
}


Junilu - [How to Ask Questions] [How to Answer Questions]
Kamlesh Dhawale
Greenhorn

Joined: Aug 15, 2002
Posts: 8
if I define a public String[] getMulOpt() in the actionform class, I get the follwoing error:
java.lang.NoSuchMethodError: myForm.getMulOpt()Ljava/lang/String;
It does not give any errror if I define
public String getMulOpt()
But then it does not populate the values.
I have public void setMulOpt(String[] values) already defined.
The html snippet for this is

<html:select property="mulOpt" size="5" multiple="true">
<html ptions collection= "mulbean" property="id" labelProperty="name"/>
</html:select>
Kamlesh Dhawale
Greenhorn

Joined: Aug 15, 2002
Posts: 8
Thanks, Junilu
It worked!!!
I was having problems since my build was not clean.
Thanks again
Sudharsan Govindarajan
Ranch Hand

Joined: Jul 03, 2002
Posts: 319
Thanks Junilu, I was looking for this solution.
Thanks to Kamlesh for raising this


Sudharsan


Joy is a radiation
 
jQuery in Action, 2nd edition
 
subject: How to populate ActionForm class for html:select mutiple="true" values?