0

MVVM form can't take Checkbox

asked 2012-09-12 15:30:08 +0800

davout gravatar image davout
1429 3 18

updated 2013-03-27 09:49:53 +0800

jimyeh gravatar image jimyeh
2047 1 4
ZK Team

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

delete flag offensive retag edit

Comments

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

3 Answers

Sort by ยป oldest newest most voted
1

answered 2012-09-20 11:08:05 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

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>

link publish delete flag offensive edit
0

answered 2012-09-20 11:01:00 +0800

benbai gravatar image benbai
2228 6
http://www.zkoss.org

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

link publish delete flag offensive edit
0

answered 2013-03-22 07:14:37 +0800

ajaidka gravatar image ajaidka
196 4

a) Use boolean instead of Boolean b) getter should start with is e.g isVisible instead of getVisible

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2012-09-12 15:30:08 +0800

Seen: 437 times

Last updated: Mar 27 '13

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More