File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Spring and the fly likes form:options runtime error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "form:options runtime error " Watch "form:options runtime error " New topic
Author

form:options runtime error

albert kao
Ranch Hand

Joined: Feb 04, 2010
Posts: 245
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)
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
albert kao
Ranch Hand

Joined: Feb 04, 2010
Posts: 245
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
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

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

Joined: Feb 04, 2010
Posts: 245
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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: form:options runtime error