• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Kamlesh Dhawale
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Junilu Lacar
Bartender
Pie
Posts: 7747
60
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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;
}
 
Kamlesh Dhawale
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Junilu
It worked!!!
I was having problems since my build was not clean.
Thanks again
 
Sudharsan Govindarajan
Ranch Hand
Posts: 319
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Junilu, I was looking for this solution.
Thanks to Kamlesh for raising this


Sudharsan
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic