我對ZK應用程序有很大的(對我來說)問題。我想綁定模型查看,但它不起作用。當我嘗試做小程序訪問模型,我得到錯誤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 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(‘初始化’)」一切都很好
請顯示異常的完整堆棧跟蹤。 –
請不要發佈其他信息作爲答案。你可以也應該編輯你的問題來做到這一點。 –