0

How to pass a dynamic data as a argument of js function in .ZUL

asked 2015-08-05 11:43:33 +0800

Jagannath gravatar image Jagannath
1

I have a requirement to call a js function by zul file. Below is the code

<radio id="${processChecklistBean.folderProcessChecklistRecord.checklistCode}" value="Y"
 label="${param['processChecklistBean.folderProcessChecklistRecord.checklistCode']}"
 onClick='Clients.evalJavaScript("myfunc(processChecklistBean.folderProcessChecklistRecord.checklistCode)")'/>

I need to send the id of above radio button to that function which is dynamically created. can you help me the right syntax for it.

below is the code for js function.

<script type="text/javascript"> function myfunc(code) { alert(code); } </script>
delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2015-08-05 12:24:58 +0800

Darksu gravatar image Darksu
1991 1 4

Hello Jagannath,

I created the following code so that you can use as a reference:

Zul:

<zk>
    <script type="text/javascript">
        function doTest (code) {
          alert(code)
            zAu.send(new zk.Event(zk.Widget.$('$btn'), 'onTest', null), 10);
        }
    </script>
    <window apply="org.zkoss.bind.BindComposer"
        viewModel="@id('vm') @init('pkg$.TestVM2')">
        <div width="200px">
            <label value="@load(vm.msg)" style="width: 300px;" />
        </div>

        <button id="btn" label="test" onClick="@command('test')" />

    </window>
</zk>

Java:

package pkg$;


import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.NotifyChange;
import org.zkoss.zk.ui.util.Clients;
public class TestVM2 {
    private String _msg = "before test";

    public String getMsg() {
        return _msg;
    }

    @Command @NotifyChange("msg")
    public void test() {
        _msg = "Js Function test";

        String command = String.format("doTest('%s');", _msg);
        Clients.evalJavaScript(command);

    }



}

You just have to make so small changes to the code.

Best Regards,

Darksu

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-08-05 11:43:33 +0800

Seen: 80 times

Last updated: Aug 05 '15

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