• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

form:options runtime error

 
Ranch Hand
Posts: 260
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to present a choice of provinces with the Spring 2.5.6 form:options.
I have defined getProvince and setProvince functions.
Please help to solve the following run time error.
Thanks.

UserCommand.java
[code]public class UserCommand {

private String province;
private String[] provinces = {
"AB",
"BC",
"MB",
"NB",
"NL",
"NT",
"NS",
"NU",
"ON",
"PE",
"QC",
"SK",
"YT"
};

public String getProvince() {
return province;
}

public void setProvince(String province) {
this.province = province;
}

public String[] getProvinces() {
return provinces;
}

public void setProvinces(String[] provinces) {
this.provinces = provinces;
}

}
[/code]

addUser.jsp
[code]<form:form method="POST" action="" commandName="addUserCommand">
<table>
<tr>
<td align="right">Province:</td>
<td><form:select path="province" size="15">
<form:options items="${addUserCommand.provinces}" itemLabel="provinceName" itemValue="province"/>
</form:select>
</td>
</tr>
</table>
</form:form>[/code]


Runtime error with eclipse:
16:44:52,312 ERROR org.springframework.web.servlet.tags.form.OptionsTag:84 - Invalid property 'province' of bean class [java.lang.String]: Bean property 'province' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
org.springframework.beans.NotReadablePropertyException: Invalid property 'province' of bean class [java.lang.String]: Bean property 'province' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
at org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:540)
at org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:532)
at org.springframework.web.servlet.tags.form.OptionWriter.doRenderFromCollection(OptionWriter.java:190)
at org.springframework.web.servlet.tags.form.OptionWriter.renderFromArray(OptionWriter.java:148)
at org.springframework.web.servlet.tags.form.OptionWriter.writeOptions(OptionWriter.java:129)
at org.springframework.web.servlet.tags.form.OptionsTag.writeTagContent(OptionsTag.java:157)
at org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:90)
at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:77)
at org.apache.jsp.WEB_002dINF.jsp.addUser_jsp._jspx_meth_form_005foptions_005f0(addUser_jsp.java:780)
at org.apache.jsp.WEB_002dINF.jsp.addUser_jsp._jspx_meth_form_005fselect_005f0(addUser_jsp.java:741)
at org.apache.jsp.WEB_002dINF.jsp.addUser_jsp._jspService(addUser_jsp.java:292)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would remove itemLabel and itemValue attributes as it is trying to call the get method on the Strings that are in the array, and not your Command object. It is already tied to your command object with your <form:select> tag.

Mark
 
albert kao
Ranch Hand
Posts: 260
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mark Spritzler wrote:I would remove itemLabel and itemValue attributes as it is trying to call the get method on the Strings that are in the array, and not your Command object. It is already tied to your command object with your <form:select> tag.

Mark



Your solution works.
Thanks!!!

A related question:
The provinces display the entire choice on the screen.
How to display only one choice on the screen and the user move the mouse or the cursor key to get more choice?
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You mean like a drop down? Or something else. I thought what you had was a drop down already.

Which widget do you want?

Thanks

Mark
 
albert kao
Ranch Hand
Posts: 260
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

albert kao wrote:

Mark Spritzler wrote:I would remove itemLabel and itemValue attributes as it is trying to call the get method on the Strings that are in the array, and not your Command object. It is already tied to your command object with your <form:select> tag.

Mark



Your solution works.
Thanks!!!

A related question:
The provinces display the entire choice on the screen.
How to display only one choice on the screen and the user move the mouse or the cursor key to get more choice?



Setting the size to 1 achieve my goal.
Problem is solved!
 
reply
    Bookmark Topic Watch Topic
  • New Topic