• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Custom converter in JGoodies Binding

 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've been trying to create a custom JGoodies binding converter with no luck. Currently my model contains properties that are all simple types (strings, integers, etc). Everything is setup such that when a property changes the corresponding JLabel in my GUI changes. Okay...no problem.

But now I want to bind a custom object, not just a string or integer. So, for example I have something like the following:

My current working model class:


But now I'm trying to do something like:



I've thought that I would have to develop a custom converter (extending the com.jgoodies.binding.value.AbstractConverter class) that takes my custom object and converts it into a string representation because I then have:



but this gives me an exception:



Can anyone help?
[ October 26, 2005: Message edited by: David Irwin ]
 
David Irwin
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This should have been obvious:


Caused by: java.lang.ClassCastException: The subject value must be of type HardwareData.
at jhomenet.binding.CustomConverterFactory$DataConverter.convertFromSubject(Unknown Source)
at com.jgoodies.binding.value.AbstractConverter.getValue(AbstractConverter.java:134)



I was getting a class cast exception because the first conversion was sending something other than my CustomObject. Now I've removed this excetion and simple returns a "NULL" string instead. Now it works.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic