Reputation: 193
hi guys i am very new to ZK i am receiving 2 errors please guide me throught sorry if this errors and very easy for a not newbie. here is the code.
public void createItem(Listbox list)
{
BindingListModelList model=(BindingListModelList)list.getModel();
System.out.println((list==null));//prints false
System.out.println((model==null));//prints true
if(model==null){ list.setModel(new ListModelList());System.out.println("After Set New Model: "+(list.getModel()==null));//prints true}
model=(BindingListModelList)list.getModel();
System.out.println((model==null));//prints true
model.add(getMeridaManager().createNewMeridaItem(list));//throws NPE
}
public void loadGrid(Listbox list)
{
//here i load the model but when is a empty ALL arrayList throws exception on createItem(Listbox list)
java.util.List<DianaMerida>all = meridaManager.getAllMeridas();
BindingListModelList rl=new BindingListModelList(all,false);
list.setModel(rl);
}
here if the .zul when i uses the past code. i was wonder if is a empty collection how can i add new items to the model by example a add new record later.
2 question i have the following code in a zul.
checkbox id="isclosecheckbox" checked="@{d.c03}" onCheck="myClass.checkBoxListener2(datebox1);"
datebox id="datebox1" cols="10" format="short" mold="rounded"
but when the checkBox is clicked and the myClass.checkBoxListener2(datebox1);
method is called i get the following error.
03/02/2013 04:30:41 PM org.zkoss.zk.ui.impl.UiEngineImpl handleError:1280 GRAVE: >>org.zkoss.zk.ui.UiException: Sourced file: inline evaluation of:
. . . '' : Undefined argument: datebox1 : at Line: 300 : in file: inline evaluation of:
. . . '' : ( datebox1 )Sourced file: inline evaluation of:
. . . '' : Undefined argument: datebox1 : at Line: 300 : in file: inline evaluation of:
. . . '' : ( datebox1 )
Upvotes: 0
Views: 1623
Reputation: 13492
If you are using MVVM architecture you can add a new item in listbox like this..
<?page title="new page title" contentType="text/html;charset=UTF-8"?>
<zk>
<window title="new page title" border="normal"
viewModel="@id('vm') @init('com.team.MyListbox')" apply="org.zkoss.bind.BindComposer">
<button label="AddItem" onClick="@command('addNewItem')"></button>
<listbox model="@bind(vm.dataList)">
<listhead>
<listheader value="A"></listheader>
<listheader value="B"></listheader>
<listheader value="C"></listheader>
</listhead>
<template name="model" var="mymodel">
<listitem>
<listcell>
<textbox value="@bind(mymodel.a)" />
</listcell>
<listcell>
<label value="@bind(mymodel.b)" />
</listcell>
<listcell>
<label value="@bind(mymodel.c)" />
</listcell>
</listitem>
</template>
</listbox>
</window>
</zk>
And Java Code or ViewModel is...
package com.team;
import java.util.ArrayList;
import java.util.List;
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.bind.annotation.NotifyChange;
import org.zkoss.zk.ui.Component;
public class MyListbox {
private List<Data> dataList;
@AfterCompose
public void afterCompose(@ContextParam(ContextType.VIEW) Component view) {
try {
dataList = new ArrayList<Data>();
Data data;
data = new Data("a1", "b1", "c1");
dataList.add(data);
data = new Data("a2", "b2", "c2");
dataList.add(data);
data = new Data("a3", "b3", "c3");
dataList.add(data);
} catch (Exception e) {
}
}
@Command
@NotifyChange("dataList")
public void addNewItem(){
Data data = new Data("", "", "");
dataList.add(data);
}
public List<Data> getDataList() {
return dataList;
}
public void setDataList(List<Data> dataList) {
this.dataList = dataList;
}
public class Data {
String a;
String b;
String c;
public String getA() {
return a;
}
public String getB() {
return b;
}
public String getC() {
return c;
}
public void setA(String a) {
this.a = a;
}
public void setB(String b) {
this.b = b;
}
public void setC(String c) {
this.c = c;
}
public Data(String a, String b, String c) {
super();
this.a = a;
this.b = b;
this.c = c;
}
}
}
And for your checkbox issue you can use code in zul something like this..
<checkbox checked="@bind(vm.checkboxValue)" onCheck="@command('checkboxClicked' />
Here i bind checkbox value with this variable
checkboxValue
and anyone click on the checkbox i am calling a method
checkboxClicked
where i can perform my business logic
Upvotes: 1