• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Using Property Editors With Spring

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there!

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?

Thanks for the atention

Stevie
[ May 11, 2007: Message edited by: Stevie Braga ]
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Stevie Braga
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nick,

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.
 
Nick Williamson
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
it's a teeny, tiny, wafer thin ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic