ZK 使用Clients.response

时间:2022-12-06 16:38:26

参考:

http://*.com/questions/11416386/how-to-access-au-response-sent-from-server-side-at-client-side

前台(test.zul):

<?page title="Listbox使用" contentType="text/html;charset=UTF-8"?>
<zk xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.zkoss.org/2005/zul"
xsi:schemaLocation="http://www.zkoss.org/2005/zul http://www.zkoss.org/2005/zul">
<window border="normal" apply="test.ListboxCtrl"> <script type="text/javascript">
zAu.cmd0.myClientHandler = function (greet, person) {
alert(greet + person);
}
</script> </window>
</zk>

后台(ListboxCtrl.java):

package test;

import org.zkoss.zk.au.AuResponse;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.util.Clients;
import org.zkoss.zk.ui.util.GenericForwardComposer; public class ListboxCtrl extends GenericForwardComposer<Component>{ private static final long serialVersionUID = 1L; String hel = "hello";
String wor = "world"; @Override
public void doAfterCompose(Component comp) throws Exception {
// TODO Auto-generated method stub
super.doAfterCompose(comp); AuResponse response = new AuResponse("myClientHandler", new Object[]{hel,wor});
Clients.response(response); } }