Hi all,
I am running into a situation that must be common with Spring MVC, but I can't seem to find any previous posts covering it.
I have a domain object that contains a map. I am using this domain object as a form backing bean and would like to be able to manipulate the objects in the hash via a form. This is no problem, I can retrieve the objects from the map in my view and bind to them with code like:
Easy! I can pull the objects out of the map, by key, because freemarker is very powerful.Code:<#if object.objMap?keys?seq_contains(foo)> <fieldset class="displayObjectValues"> <@spring.formInput "object.objMap[foo].message1"/> <@spring.bind"object.objMap[foo].message1"/>${spring.status.errorMessage}</p> ......
The problem is with validation. I can pull the objects out of the map using standard Java syntax, I can run my checks on them, but I can't specify the "field" in my rejectValue calls.
This code should make it clearer:
What do I put instead of ??????? ? How do I reference this object that was pulled out the map? What is it's fieldname?Code:fooObject = (FooObject)obj.getObjMap.get("foo"); if (foo.getMessage1() < MIN_MESSAGE_LENGTH) { err.rejectValue("???????", "otpLengthTooShort", "You cannot generate messages that are less than " + MIN_MESSAGE_LENGTH + " characters long"); }
My problem (as you can see) is that this isn't a simple object1.object2.field case. Because I am using a map to store objects I can't use the standard . notation.
Is there some notation that I can use in the rejectValue call for the field that will allow me to bind an error to a particular field, from a given key in the map? Alternatively, is there some trick that I am missing?
Thanks for your help with this,
Cheers,
Deakin


Reply With Quote