This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Spring and the fly likes form binding with generic types Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "form binding with generic types" Watch "form binding with generic types" New topic
Author

form binding with generic types

jan dressen
Ranch Hand

Joined: Oct 25, 2007
Posts: 47
I have a use case where I need to bind a text field of a webpage to a bean which is declared as an interface type but instantiated as some Class which offcourse implements this interface.
when Spring tries to find a converter to convert the String(from the webpage) to the actual type to which it should bind it only checks how this bean is declared, not how it is instantiated. and I do not have a converter to convert the String to this interface.

Does anyone know how I can solve this problem? Maybe something with a Custom Editor?
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Can you, in code figure out the class implementation to instantiate?

I have done heirarchies like that in PropertyEditors and I am sure I can do that in a Converter class too.

How do you determine what type of implementation to instantiate?

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
jan dressen
Ranch Hand

Joined: Oct 25, 2007
Posts: 47
Mark Spritzler wrote:Can you, in code figure out the class implementation to instantiate?

I have done heirarchies like that in PropertyEditors and I am sure I can do that in a Converter class too.

How do you determine what type of implementation to instantiate?

Mark


can you point me in the right direction on how to do this in a custom editor?

I think I cannot figure out what type to instantiate because the BeanWrapperImpl only gives me the sourceType and TargetType, which it retrieved trough reflection and only from the signature of the property(the interface) not the actual implementation. If somehow the BeanWrapperImpl gave me the OldValue(which does contain the actual type) then I can get the value I should bind to. But for some reason the oldValue is always null...
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: form binding with generic types
 
Similar Threads
How to display Hibernate Set to JSF Datatable
Date problem
Custom Converter - Java Studio Creator
jsp:include directive and backing beans
Polymorphism OO Design Question