-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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?
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{
}
Asked: 2017-11-09 18:31:05 +0800
Seen: 10 times
Last updated: Nov 10 '17
Facing issue in masking on phone [closed]
coerceFromString_ override no longer works from 6.5.1 [closed]
Execute Javascript on component visible
Is there a way to resolve view model properties as input to client side javascripts?
scrollbar listner for 2 grid [closed]
Theme javascript wpd file not found
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 )editZK mechanism doesn't change. The reason of
hawk ( 2017-11-13 10:09:26 +0800 )edit@ToServerCommand
doesn't work is that your ViewModel binding syntax is wrong, so ZK doesn't actually create the ViewModel object.