Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

form binding with generic types

 
jan dressen
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
jan dressen
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic