-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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')">
</window>
and finally in the view model:
@Command
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!
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
Asked: 2014-07-10 16:40:32 +0800
Seen: 50 times
Last updated: Jul 14 '14
client onSize event - Before size changes?
How to stop combining commands in an ajax call ?
zk.auSend not called on composer
Font Awesome Problem with IE8 when security option "font download" is disabled
How to capture the Browser Window Resize/Size Event
Toggled Popup - Close ONLY on toggling, not on focus lost
Verify existence -Verificar existencia DNI
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 )editThanks 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 )editWell done my friend... well done!
cyiannoulis ( 2014-07-16 14:50:53 +0800 )edit