0

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.

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

        }
    </script>

@Listen("onShowNotification=#deviceSetup")
public void onShowNotification() {
    Message.showSuccessNotification(ResourceBundle.get("MonitorAlert:NO_NOTIFICATION_AVALABLE"));
}
delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
2

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

cyiannoulis gravatar image cyiannoulis
1191 10

The following example will do the trick:

<zk>
<window border="none" height="100%" width="100%"
        xmlns:w="client" xmlns:n="native"
        apply="org.zkoss.bind.BindComposer" 
        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">
<![CDATA[   

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

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

]]></script>

</window>
</zk>

and the command in your view model:

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

hope that helps

Costas

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

Follow
1 follower

RSS

Stats

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