data binding

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view

data binding

My question:

I wish to attach userData to my custom component.  I attach it to my object
by putting it into the UserData dictionary 

Now  I wish to get it.  however I wish to have my constructor decode some of it for display so that the skin comes up with the decoded version. 

 I am not sure the best way to do this. Can someone suggest?

I have so far :

MyComponent myComponent = new MyComponent();
mycomponent.getUserData.put("file", file);

now in my constructor :

MyComponent() {
file = (File)this.getUserData().get("file");
decodeData();  ??????

File file;

but this bad form since the constructor is building the class as I would be
called a method of the class.
So If I remove decodeData from the constructor and make it a public method I
can call :


However I am unsure how to get my decoded data entries into the user
directory without explicitly putting them in. i would like access the same
way that the styles dictionary works, ie. the setThis(), setThat()
methodology where This and That are then styles in the Styles dictionary.
Does UserData dictionary have an equivalent.

Reply | Threaded
Open this post in threaded view

RE: data binding

Roger Whitcomb-2

Hi Cynthia,

So, let me see if I understand:

·         You want to be able to iterate over the user data entries that have already been set and call “setXXX” methods in the component based on the key names in the user data dictionary?


If that’s what we’re talking about, then I would suggest the “BeanAdapter” class.  This provides the link I think you’re talking about between a property named “foo” and the “setFoo” and “getFoo” methods on an object.


If I understand the question, then your “decodeData()” method in the component would look something like this:


public void decodeData() {

                BeanAdapter adapter = new BeanAdapter(this);

                Dictionary<String, Object> dict = getUserData();

                for (String key : dict) {

                                adapter.put(key, dict.get(key));




Then, of course, you would have to implement each of the “setXXX” methods in your component so that the BeanAdapter can find them.


Does that help?

~Roger Whitcomb