-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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>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
Asked: 2015-08-05 11:43:33 +0800
Seen: 89 times
Last updated: Aug 05 '15