我对zk应用程序有很大的问题(对我而言)。我想将模型绑定到视图但它不起作用。当我尝试在模型中访问applet时,我得到错误java.lang.NullPointer
//index.zul
<?page title="Auto Generated index.zul"?>
<window id="mainWindow" title="edycja dokumentow" border="normal"
apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm') @init('controller.EditDocsController')">
<vbox>
<listbox id="modelList" height="160px" model="@bind(vm.modelList)">
<listhead>
<listheader label="id" />
<listheader label="open" />
</listhead>
<template name="model">
<listitem>
<listcell label="@bind(each)" />
<listcell >
<button label="otworz" onClick="@command('open',id=each)"/>
</listcell>
</listitem>
</template>
</listbox>
<applet code="applet.EditFileApplet" codebase="applet" archive="EditApplet.jar" width="100px" height="100px" model="@save(vm.editApplet) before='open'"/>
<!--<applet code="applet.EditFileApplet" codebase="applet" archive="EditApplet.jar" width="100px" height="100px" model="@bind(vm.editApplet)'"/>
// I have tried these two version separetly
</vbox>
</window>
EditDocsController.java
public class EditDocsController {
private DocsDAO docksDAO = new DocsDAO();
private List<Integer> modelList;
private Applet editApplet;
public Applet getEditApplet() { return editApplet; }
public void setEditApplet(Applet editApplet) { this.editApplet = editApplet; }
public List<Integer> getModelList() { return modelList; }
public void setModelList(List<Integer> modelList) { this.modelList = modelList; }
@AfterCompose
public void loadDock(){
modelList = docksDAO.getData();
/* editApplet = new Applet();
editApplet.setCode("applet.EditFileApplet");
editApplet.setCodebase("applet");
editApplet.setArchive("EditApplet.jar");*/
}
@Command
public void open(@BindingParam("id") Integer id){
editApplet.getArchive();
editApplet.invoke("open", new String[]{id.toString(),"user jakiś tam"} );
}
}
提前谢谢,
如果你有任何想法如何修复它,请与我分享
这里是所有堆栈跟踪https://docs.google.com/document/d/1YZs7xgzxbOGo70sPogUdNn5IbwWGcq2YU1GRszEtdNk/edit?usp=sharing
这是它的一部分,对我来说它是最有价值的
lut 28, 2014 1:19:56 PM org.zkoss.bind.impl.ParamCall call
SEVERE:
java.lang.NullPointerException
at controller.EditDocsController.open(EditDocsController.java:51) // the line editApplet.getArchive()
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
lut 28, 2014 1:19:56 PM org.zkoss.bind.impl.BinderImpl$CommandEventListener onEvent
SEVERE: null
java.lang.NullPointerException
at controller.EditDocsController.open(EditDocsController.java:51)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
lut 28, 2014 1:19:56 PM org.zkoss.zk.ui.impl.UiEngineImpl handleError
SEVERE:
java.lang.NullPointerException
at controller.EditDocsController.open(EditDocsController.java:51)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
lut 28, 2014 1:21:21 PM org.zkoss.bind.impl.BinderImpl addPropertySaveBindings0
WARNING: component <Applet xLDQ7#myEditApplet> doesn't has event to save attribute model at [file:/C:/Users/bbur/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/RPO/index.zul, line:30]
我已经对代码进行了一些更改以解决问题,但仍然存在问题。我用它来初始化applet
<applet id="myEditApplet" code="applet.EditFileApplet" codebase="applet" archive="EditApplet.jar" width="30px" height="30px" style="border: 1px" />
将按钮定义更改为
<button label="otworz" onClick='myEditApplet.invoke("openDoc","1234")'/>
我删除了从EditDocsController打开的方法
当我点击“otworz”按钮时,我收到错误“无法调用applet的方法:openDoc undefined“尽管applet类中存在该方法(public void openDoc(String idDoc))。最烦人的事情是,当我调用'myEditApplet.invoke(”init“)时,一切都很好
答案 0 :(得分:0)
ZK中的Applet
组件没有model
属性,因此您无法使用它在viewmodel中保存applet引用。 (通常model
属性不用于此)
相反,您可以为applet分配一个id,并将该id作为第二个参数传递给open
命令,如下所示:
<强> index.zul 强>
...
<button label="otworz" onClick="@command('open', id=each, applet=editApplet)"/>
...
<applet id="editApplet" code="applet.EditFileApplet" codebase="applet"
archive="EditApplet.jar" width="100px" height="100px"/>
...
<强> EditDocsController.java 强>
...
@Command
public void open(@BindingParam("id") Integer id,
@BindingParam("applet") Applet applet){
applet.invoke("open", new String[]{id.toString(),"user jakiś tam"} );
}