Author Topic: retrieving data from EventUserDataChanged in Java  (Read 7099 times)

s.kulku

  • Guest
retrieving data from EventUserDataChanged in Java
« on: May 10, 2007, 05:35:32 PM »
Hi,

can someone please be so kind as to give me an example of how to retrieve attach data that comes with the event? In Java please!

Thank you so much!

Sanja Kulku

Offline René

  • Administrator
  • Hero Member
  • *****
  • Posts: 1832
  • Karma: 62
Re: retrieving data from EventUserDataChanged in Java
« Reply #1 on: May 10, 2007, 08:40:19 PM »
Hi Sanja,

The code to retrieve particular key from UserData coming with an event please use the following code:

--- for string value
[font=Courier]<event object>.getUserData.getPair("<key name>").getStringValue();[/font]

--- for integer value
[font=Courier]<event object>.getUserData.getPair("<key name>").getIntValue();[/font]

I wasn't able to test it... Hope it will work.

René

Marked as best answer by on Today at 02:07:00 AM

Offline victor

  • Administrator
  • Hero Member
  • *****
  • Posts: 1416
  • Karma: 18
Re: retrieving data from EventUserDataChanged in Java
« Reply #2 on: May 11, 2007, 07:32:12 AM »
  • Undo Best Answer
  • Hi, René and Sanja,

    I looked at Java SDK and it is really cumbersome to retrieve all the attach-data there.

    I have found Enumaration and Iteration not to work properly - using  .getEnumeration() to return an enumerator would fail to deliver what I need - it would return the hasMoreElements = false even though I can clearly see is as being loaded with at least three sets of key-value pair.

    I have also failed to get KeyValueCollection do anything useful on its own. Unlike C#, there is no .Keys member to give you all the keys! (At least I don't know how).

    Here is how I have managed to get it working... It might not be the smartest way, but at least it works!


              KeyValueCollection attach_data = event.getUserData();

              Object[] arr = attach_data.toArray();
                                           
                int count;
                for (count = 0; count < arr.length; count++) {
                    KeyValuePair kvp = (KeyValuePair)arr[count];
                }

    I hope this will make your life a bit easier  :P
    I really wish there was a simple way to map KeyValueCollection into KVP pairs!!! And if someone knows how to do it (my way is simply awful), PLEASE tell me.

    Best regards,
    Vic