0

Cannot Call java from javascript

asked 2011-11-18 20:47:10 +0800

skn gravatar image skn
12

updated 2011-11-18 20:53:20 +0800

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

delete flag offensive retag edit

3 Replies

Sort by ยป oldest newest

answered 2011-11-21 11:52:56 +0800

skn gravatar image skn
12

I fixed the problem.

link publish delete flag offensive edit

answered 2011-11-21 12:35:13 +0800

zippy gravatar image zippy
504 1 2

share the solution!!

link publish delete flag offensive edit

answered 2011-11-21 13:21:42 +0800

skn gravatar image skn
12

updated 2011-11-21 14:40:12 +0800

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));

link publish delete flag offensive edit
Your reply
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

Follow

RSS

Stats

Asked: 2011-11-18 20:47:10 +0800

Seen: 458 times

Last updated: Nov 21 '11

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