Send a client event with JSON data

asked 2014-07-10 16:40:32 +0800

Tristan2583 gravatar image Tristan2583
13 3

updated 2014-07-14 09:40:02 +0800

Hi all!

I have a simple problem: I want to fire a client event with JSON data and then manipulate this data on server. In a javascript file I have a function with this command:

result = {
                    address: result[0].formatted_address,
                    partialMatch: result[0].partial_match,
                    deepest: true,

zAu.send(new zk.Event(zk.Widget.$('$win'), 'onReverseGeocodingResultReady', result));

In the zul I have:

<window id="win" apply="org.zkoss.bind.BindComposer" viewModel="@id('gpsvm') @init('pino.masterflash.zoo105.ViewModel')" width="100%" height="100%" validationMessages="@id('vmsgs')" onReverseGeocodingResultReady="@command('showGeocodingResult')">


and finally in the view model:

public void showGeocodingResult( @ContextParam(ContextType.TRIGGER_EVENT) Event evt){

// etc.. etc.. etc..

how can I get the event data? evt.getData() is enough? How can I get the address of the JSON object?

Thanks to all!

EDIT 1: @cyiannoulis This is the format of my json

result = { address: result[0].formattedaddress, partialMatch: result[0].partialmatch, deepest: true, };

the address is in bold.

If I cast the event data then I can get the address this way?

JSONOBject result = (JSONObject)evt.getData(); String addr = result.get("address");

thanks again!

delete flag offensive retag edit


Interesting question but i don't think this is possible. As far as i know, ZK event is not capable to wrap json objects. You have to get the json data as a string and then use a json library to convert it back into a json object.

cyiannoulis ( 2014-07-15 10:30:31 +0800 )edit

Thanks for your help cyiannoulis. I found a solution. I can cast the event data to a org.zkoss.json.JSONObject and then I can access to all the fields of the JSON. For example:

JSONObject object = (JSONObject) evt.getData(); String address = object.get("address");

Tristan2583 ( 2014-07-16 13:15:40 +0800 )edit

Well done my friend... well done!

cyiannoulis ( 2014-07-16 14:50:53 +0800 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2014-07-11 11:41:26 +0800

cyiannoulis gravatar image cyiannoulis
1191 10

What do you mean "the address of the json object"? Normaly, calling the event.getData() method should return a string with your json data and then you may use a utility to convert this json data into java beans.

Hope that helps Costas

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools




Asked: 2014-07-10 16:40:32 +0800

Seen: 45 times

Last updated: Jul 14 '14

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More