-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi all,
how to call method java use Javascript, i have try like this
in zul file
<zk xmlns="http://www.zkoss.org/2005/zul"
xmlns:h="http://www.w3.org/1999/xhtml"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.zkoss.org/2005/zul
http://www.zkoss.org/2005/zul/zul.xsd"
xmlns:w="http://www.zkoss.org/2005/zk/client"
xmlns:n="http://www.zkoss.org/2005/zk/native">
<script src="js/jquery-1.7.1.min.js" type="text/javascript"/>
<script>
function doPrintIframe(){
WaitForIFrame();
resetF();
}
function WaitForIFrame(){
//display iframe
}
function resetF() {
zk.Widget.$('$CSController').fire('resetForm', null, {toServer: true});
zAu.send(new zk.Event(zk.Widget.$('$CSController'), "resetForm", {'' : {'data' : {'nodeId': ''}}}, {toServer:true}));
}
</script>
<window id="win1" hflex="1" border="normal" sizable="true" maximizable="true"
apply="${CSController},org.zkoss.bind.BindComposer">
</window>
</zk>
in java class
@org.springframework.stereotype.Component("CSController")
@Scope("prototype") public class CSalesController extends GenericForwardComposer{
@Override
public void doAfterCompose(Component comp) throws Exception {
super.doAfterCompose(comp);
}
@Command
public void resetForm() {
System.out.println("reset form processs");
}
}
but get error
[http-bio-8084-exec-20] ERROR org.zkoss.zk.ui.impl.DesktopImpl - [Desktop z_fsc:/WEB-INF/ui/sales.zul] client error: Failed to process script Cannot read property 'fire' of null (TypeError)
Thank you very much
Hi there,
Regarding the error message first:
You are using the $ selector to retrieve the widget for a ZK component with id="CSController" If there is no widget in the page associated with this component, then the result of zk.Widget.$('$CSController') will be null, and calling the .fire() function from it will result in the error shown in your message. the "client error" means that the error has happened at client side, and was sent back to the server.
Regardinge how to send and event to the server: example here: https://zkfiddle.org/sample/3l4eee1/3-send-composer-custom-event-from-JS
I trimmed a few things, to keep the essential. You can use this structure while adding your own code on top for spring, iframe, etc.)
In this case, you are most likely targeting the wrong component. In your zul file, I see a id="win1" on the window. If that's the target for your custom event, that's what you should be targetting with zk.Widget.$('$win1') to retrieve a valid widget.
To make it work you need to:
{toServer: true} is helpful, since it will force the client to send the event to the server, instead of simply using it at client-side.
Using both wgt.fire() and zAu.send() is overkill, since wgt.fire will end up doing zAu send internally. Same result, no need to send twice.
There is doc on these structures here: https://www.zkoss.org/wiki/ZKClient-sideReference/Communication/AURequests/Client-sideFiring
have a look ;)
Asked: 2020-12-08 13:49:38 +0800
Seen: 11 times
Last updated: Dec 09 '20