ZK – Communicating with the server
Using Javascript instead of zscript to calculate a value means you don’t have to communicate with the server until necessary but how do you send data back to the server? I could not find a complete answer so here is my answer below:
In your zul page you will need a textbox (hidden if you want)
<textbox id="serverComm" class="serverComm"></textbox>
Your Javascript put something like this to trigger event
zk.Widget.$($(".serverComm")).setValue("value to send");
wid = zk.Widget.$($(".serverComm"));
zAu.send(new zk.Event(wid, 'onUser', location));
In your “GenericForwardComposer” you need to listen for the event:
Textbox serverComm;
public void onUser$serverComm(Event event) throws Exception {
Event eventx = Events.getRealOrigin((ForwardEvent)event);
String test = eventx.getData().toString();
System.out.println(test);
}
So you don’t make the same mistakes I made:
- don’t make your on event like “onMyEvent” I think “onUser” is an event made just for this.
- I tried sending value without the textbox but it just did not work.
November 16, 2011
|
Posted by Ozkey
Categories:
Tags: