Access and modify attributes/objects which are not part of the form backing bean

Posted by spa on Stack Overflow See other posts from Stack Overflow or by spa
Published on 2010-03-21T10:05:27Z Indexed on 2010/03/21 10:11 UTC
Read the original article Hit count: 441

Filed under:
|
|

I use Spring MVC (via Spring Roo) to build a small web application for administering persons. In the page for creating a person the bean Person is used as form backing object (key "person" in the model map).

<form:form action="${form_url}" method="POST" modelAttribute="person">

I would like to add some attributes to the model map which can be altered by the user in the creation form. Basically, I try to add a Boolean, so that I can control which page is displayed next after the user presses the submit button.

I try to modify the Boolean (key "myBoolean" in the model map) using a simple checkbox:

<form:checkbox id="_myboolean_id" path="myBoolean"/>

However, as I am new to Spring MVC I have some difficulties here. The Boolean object is not an attribute of the form backing object. So if I try to access it the following exception is thrown (of course):

Invalid property 'myBoolean' of bean class [de.cm.model.Person]: Bean property 'myBoolean' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?

Is there are way to access a value of the model map directly? The only solution I can imagine right now is a kind of wrapper object around the class Person and my additional attributes which is used as a new form backing object. However, this is more work for a IMHO simple task. Do you have a better solution?

© Stack Overflow or respective owner

Related posts about spring

Related posts about spring-mvc