-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi,
I want to call a java function from my .zul page using javascript, but I can't get it to work.
I written a piece of code based on --> http://www.zkexamples.com/blog/posts/calling-java-controller-methods-from-within-javascript/
The example is with a GenericForwardComposer, but I'am working with a GenericAutowireComposer because when I use a GenericForwardComposer, the events (like basic onClick events arent recognized!), they aren't forwarded.
The javascript function is called (alerts are displayed), but the event isn't recognized!
My .zul page:
<?page contentType="text/html;charset=UTF-8"?> <zk> <script type="text/javascript"> pm.bind("ComponentToParent", function(data) { alert("FROM CHILD: " + JSON.stringify(data)); zAu.send(new zk.Event(zk.Widget.$(this), 'onMessage', JSON.stringify(data))); alert("EVENT SEND!"); }); ... </script> <window id="windowComponent" border="none" apply="ComponentController" style="background:transparent;"> ... </window> </zk>
And this is the .java composer class
public class ComponentController extends GenericAutowireComposer { public void doAfterCompose(Component component) throws Exception { super.doAfterCompose(component); component.addEventListener("onMessage", new EventListener() { public void onEvent(Event event) throws Exception { onMessage(); } }); } public void onMessage() throws InterruptedException { Messagebox.show("MESSAGE FROM CHILD RECEIVED IN PARENT'S JAVA"); } }
Thanks
I had to adapt he zAu.send command, the widget wasn't correctly loaded!
zAu.send(new zk.Event(zk.Widget.$(jq('$windowComponent')[0]), 'onMessage', data));
Asked: 2011-11-18 20:47:10 +0800
Seen: 458 times
Last updated: Nov 21 '11