Win a copy of Pipeline as Code this week in the Cloud/Virtualization forum!
  • 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
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

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.
 
If you were a tree, what sort of tree would you be? This tiny ad is a poop beast.
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic