-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi
First Example
<window apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm') @init('com.product.webapp.Example.JavaScriptExampleVM')">
<script src="/js/javascriptexample.js"></script>
<textbox id="hai" value="HAI"></textbox>
<button id="btn" label="test" onTest="@command('onTest')" />
<button label="Click Here"
xmlns:w="http://www.zkoss.org/2005/zk/client" w:onClick="doTest();">
</button>
</window>
Java script
function doTest() {
var txtaddress = zk.Widget.$("$hai");
txtaddress.setValue("senthil");
zk.Widget.$("$hai").setValue("senthil");
zAu.send(new zk.Event(zk.Widget.$('$btn'), 'onTest', zk.Widget.$('$hai').getValue()), 10);
}
Now after clicking the button, the text box should have the value "Senthil", but still shows the same value.
But instead of referring the Java script , just include on the same zul, then it is working fine as follows
<window apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm') @init('com.product.webapp.Example.JavaScriptExampleVM')">
<script type="text/javascript">
</script>
<textbox id="hai" value="HAI"></textbox>
<button id="btn" label="test" onTest="@command('onTest')" />
<button label="Click Here"
xmlns:w="http://www.zkoss.org/2005/zk/client" w:onClick="doTest();">
</button>
</window>
Here is MVVM
package com.product.webapp.Example;
import org.zkoss.bind.annotation.AfterCompose; import org.zkoss.bind.annotation.Command; import org.zkoss.bind.annotation.ContextParam; import org.zkoss.bind.annotation.ContextType; import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.select.Selectors; import org.zkoss.zul.Messagebox;
public class JavaScriptExampleVM {
@AfterCompose
public void initSetup(@ContextParam(ContextType.VIEW) Component view) {
Selectors.wireComponents(view, this, false);
}
@Command
public void onTest(@ContextParam(ContextType.TRIGGER_EVENT) Event event) {
Messagebox.show("Hi " + event.getData().toString());
}
}
There is event onTest in btn component
<button id="btn" label="test" ontest="@command('onTest')"/>
Asked: 2013-10-14 17:13:00 +0800
Seen: 17 times
Last updated: Oct 15 '13
Facing issue in masking on phone [closed]
coerceFromString_ override no longer works from 6.5.1 [closed]
Execute Javascript on component visible
Is there a way to resolve view model properties as input to client side javascripts?
scrollbar listner for 2 grid [closed]
Theme javascript wpd file not found