0

Unable to invoke serverside java method

asked 2017-11-09 18:31:05 +0800

tisaksen gravatar image tisaksen
34 4

updated 2017-11-09 19:21:27 +0800

Hi

I have a viewmodel with the following method:

@Command public void test() { Messagebox.show("Yey!!"); }

In the zul:

<div id="dataController" viewModel="com.company.DataController">...</div>

I then try to invoke the server side method as follows:

zk.Widget.$('$dataController').fire('test', null, {toServer:true})

or

var widget = zk.Widget.$('$dataController'); zAu.send(new zk.Event(widget, "test", {toServer:true}));

But it's not working. Any tips?

delete flag offensive retag edit

Comments

I came across @ToServerCommand and got it working but I don't really understand - has the mechanism changed from what I tried to do in my example above ?

tisaksen ( 2017-11-09 19:54:22 +0800 )edit

ZK mechanism doesn't change. The reason of @ToServerCommand doesn't work is that your ViewModel binding syntax is wrong, so ZK doesn't actually create the ViewModel object.

hawk ( 2017-11-13 10:09:26 +0800 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2017-11-10 16:59:10 +0800

hawk gravatar image hawk
2028 1 5
http://hawkphoenix.blogsp... ZK Team

updated 2017-11-10 17:00:18 +0800

ViewModel syntax is incorrect, it should be:

<div viewModel="@id('vm')@init('com.company.DataController')"/>

to invoke a command method, we suggest using command binding first.

If you need to invoke a command method in javascript, please check client binding API

//get a binder
var binder = zkbind.$('$dataController');
binder.command('test', null);

ViewModel

@ToServerCommand("test")
public class DataController{
}
link publish delete flag offensive edit

Comments

Thanks a lot!

tisaksen ( 2017-11-10 17:22:57 +0800 )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

Follow
1 follower

RSS

Stats

Asked: 2017-11-09 18:31:05 +0800

Seen: 9 times

Last updated: Nov 10