-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I've posted this as a bug, but I want to check to see that I'm not doing something dumb.
Following the MVVM listbox CRUD example, Ive found that if you include a checkbox in the form the app throw an error with:
Error writing 'checked' on type org.zkoss.zul.Checkbox crash
I'm using R6.0.2
Hi davout,
I have tried a similar case with ZK 6.0.2, please refer to the sample below:
listbox_with_checkbox.zul
<zk> <window apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('test.TestVM')"> <listbox model="@load(vm.model)"> <template name="model" var="each"> <listitem> <listcell label="@bind(each.index)" /> <listcell> <checkbox checked="@bind(each.checked)" onCheck="@command('updateCheckedMsg')" /> </listcell> </listitem> </template> </listbox> <button label="add row" onClick="@command('addRow')" /> <button label="remove checked row" onClick="@command('removeSelected')" /> <textbox value="@load(vm.msg)" /> </window> </zk>
TestVM.java
package test; import java.util.ArrayList; import java.util.List; 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.event.CheckEvent; import org.zkoss.zul.ListModelList; import org.zkoss.zul.Listcell; public class TestVM { private ListModelList _model; private int _currentIndex = 0; // increase forever private String _msg = ""; public ListModelList getModel () { if (_model == null) { List l = new ArrayList(); _model = new ListModelList(l); } return _model; } public String getMsg () { return _msg; } @Command @NotifyChange({"model", "msg"}) public void addRow () { _currentIndex += 1; _model.add(new CellCnt(_currentIndex, false)); _msg = "Row " + _currentIndex + " is created"; } @Command @NotifyChange({"model", "msg"}) public void removeSelected () { List tmp = new ArrayList(); for (int i = 0; i < _model.getSize(); i++) { if (!((CellCnt)_model.getElementAt(i)).getChecked()) { tmp.add(_model.getElementAt(i)); } } _model = new ListModelList(tmp); _msg = "Checked rows are deleted."; } @Command @NotifyChange({"msg"}) public void updateCheckedMsg (@ContextParam(ContextType.TRIGGER_EVENT) CheckEvent event) { String label = ((Listcell)event.getTarget().getParent().getPreviousSibling()).getLabel(); _msg = "checkbox " + label + " is " + (event.isChecked()? "checked" : "unchecked"); } }
CellCnt.java
package test; public class CellCnt { private int _index; private boolean _checked; public CellCnt (int index, boolean checked) { _index = index; _checked = checked; } public void setIndex (int index) { _index = index; } public int getIndex () { return _index; } public void setChecked (boolean checked) { _checked = checked; } public boolean getChecked () { return _checked; } }
However, there seems some issue if you remove CellCnt from model directly (that's why I create a new model in removeSelected function), could you provide the link to the bug you posted so I can add a sample?
Thanks,
Ben
I did same thing and it worked fine for me
<x:td width="38%"> <listbox id="chosenLb" vflex="1" width="100%" height="135px" model="@load(vm.chosenDataModel)"> <listhead sizable="true"> <listheader> <x:table width="100%"> <x:tr> <x:td width="90%"> <label value="Selected Column List" style="font-weight: bold"> </label> </x:td> <x:td width="10%"> <label value="Ascending" style="font-weight: bolder"> </label> </x:td> </x:tr> </x:table> </listheader> </listhead> <template name="model" var="selected"> <listitem> <listcell> <x:table width="100%"> <x:tr> <x:td width="90%"> <label value="@bind(selected.columnHeaderName)" style="width:200px"> </label> </x:td> <x:td width="10%"> <checkbox checked="@bind(selected.sortAscending)" style="align:right;width:50px" onCheck="@command('checkboxClicked',item=selected.sortAscending,check=self.checked)" /> </x:td> </x:tr> </x:table> </listcell> </listitem> </template> </listbox> </x:td>
Asked: 2012-09-12 15:30:08 +0800
Seen: 450 times
Last updated: Mar 27 '13
Is there a way to resolve view model properties as input to client side javascripts?
How to Call Child ViewModel Method from Parent Window? [closed]
zk mvvm focus textbox after a button clicked
ZK MVVM Listbox Mold Paging - select first record on each page [closed]
zul.mesh.wpd this.$n().style is null
Redirect modal window without changing parent window. [closed]
This problem seems new to R6.0.2. My original code was written against R6.0 and worked fine.
davout ( 2012-09-12 16:25:00 +0800 )edit