Call JavaScript function from ViewModel

asked 2016-06-14 07:32:53 +0800

kleponboy gravatar image kleponboy flag of Indonesia
54 5


I want to call JavaScript function via init method in the ViewModel, It always throw an error "onLoad is not defined".

my jsTest.js :

 function onLoad(){

my test.zul :

<div apply="org.zkoss.bind.BindComposer"
    viewModel="@id('vm') @init('com.test.TestViewModel'>

  <script type="text/javascript" src="jsTest.js"></script>


and myViewModel :

public void init(){
  Clients.evalJavaScript("onLoad()");//Throws an error


but if I try called the function via button onClick event it will run just fine.

public void callFunction(){
   Clients.evalJavaScript("onLoad()");//No error

Pls Help,

Regards, Klepon

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted

answered 2016-06-14 08:50:37 +0800

gganassin gravatar image gganassin flag of Luxembourg
540 6


1 - i'd put also the ; char inside the Clients.evalJavaScript("onLoad();"); 2 - Try to move the <script> tag before the

as i think it is still not loaded when the @init is triggered (binder calls the method with this annotation when initializing a ViewModel)


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: 2016-06-14 07:32:53 +0800

Seen: 30 times

Last updated: Jun 14 '16

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