• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

form binding with generic types

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
reply
    Bookmark Topic Watch Topic
  • New Topic