How to call java method from javascript in zul in mvvm

asked 2015-09-02 06:40:50 +0800

virat gravatar image virat
46 3

updated 2015-09-02 07:04:00 +0800

Anyone can help me please.

        function demo(demo,flag){ if(flag == 'true'){ return false; }
         zAu.send(new zk.Event(zk.Widget.$(this), 'onShowNotification',[null]));, {
              toServer: true


public void onShowNotification() {
delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted

answered 2015-09-02 08:18:06 +0800

cyiannoulis gravatar image cyiannoulis
1191 10

The following example will do the trick:

<window border="none" height="100%" width="100%"
        xmlns:w="client" xmlns:n="native"
        viewModel="@id('vm') @init('YourViewModel')">

<!-- A ZK button calling a native js function -->
<button label="Fire from ZK button" w:onClick="fireEventFromClient()" />

<!-- Alternatively a native html button calling a js function -->
<n:button onClick="fireEventFromClient()">Fire from native button</n:button> 

<!-- A div listening for the event -->
<div id="listenerDiv" onShowNotification="@command('showNotification')" />

<script type="text/javascript">

 function fireEventFromClient() {
    zk.Widget.$('$listenerDiv').fire('onShowNotification', null, {toServer:true});

 function calledFromServer(msg) {
    alert("Server says: " + msg);



and the command in your view model:

   public void showNotification() {
      String message = "Hello!";
      Clients.evalJavaScript("calledFromServer('" + message + "')");

hope that helps


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

1 follower



Asked: 2015-09-02 06:40:50 +0800

Seen: 140 times

Last updated: Sep 02 '15

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