Is there a way to use Spring's form
tag to bind to fields instead of "setter" and "getter" methods?
Something like this:
public class Foo {
public String bar;
}
<form:form modelAttribute="foo">
<form:input path="bar" />
</form>
But without the use of superfluous methods:
org.springframework.beans.NotReadablePropertyException: Invalid property 'bar' of bean class ... Bean property 'bar' is not readable or has an invalid getter method
Unfortunately, I believe that the model object needs to have the bean-style getters ("getX()" or "isX()") and setters ("setX()") for the form binding tags to work properly. Most IDEs can generate these for you with a couple of keystrokes if you're finding it annoying to add them to your model classes.
You could also consider maintaining separate objects specifically for form binding if you're worried about modifications to your existing model objects -- of course that will cause additional maintenance as well.