I'm starting an application using the spring MVC, and I got this doubt: everytime I need to convert a String to a non-String property, do I have to create a new class extending java.beans.PropertyEditorSupport to use as a custom property editor or there is another way of doing that?
No, it should try and convert the string when it tries to bind, the only one I had to specifically tell was with a date, and I just set up a simpledateformat object to parse/format dates.
Joined: Apr 04, 2006
Thanks for replying, but the classes I mean are my domain classes. And my real doubt is: do I have to write a Custom Editor for everyone of my domain classes? If I have 100 classes, do I have to write 100 custom editors? I think that might be another way of doing that.
Joined: Jan 06, 2007
You have to tell Spring how to convert certain things, basically objects that don't take a string in a constructor.
In my code I use this, I have my controller that extends simple form controller and my form backing object (my domain bean) has a java.util.Date filed on it. So I put this code in my controller ...
Now if I had 100 bean that had a date for submission. I would create a form that extends SimpleFormController, put this method in it and then have all my other controllers extend this controller, that way I have this code for binding my dates in one location and I don't have to override this method for each controller.