0

Bug with MVVM listbox and checkmark and multiple?

asked 2012-08-05 13:54:17 +0800

davout gravatar image davout
1435 3 18

I'm trying to setup a MVVM listbox so that multiple items can be selected, like...

<listbox id="others" checkmark="true"
		multiple="true" selectedItems="@bind(vm.otherSelections)"
		model="@load(vm.othersModel)" vflex="true" mold="paging">
	<auxhead>
		<auxheader label="Available"
			align="center" colspan="2"/>
	</auxhead>
	<listhead>
		<listheader label="Type" sort="auto"
			hflex="min" />
		<listheader label="Name" sort="auto" />
	</listhead>
	<template name="model" var="other">
		<listitem>
			<listcell
				label="@load(other.typeTitle)" />
			<listcell
				label="@load(other.planEntityTitle)" />
		</listitem>
	</template>
</listbox>



The listbox starts empty. When I add items to it, I get a 'radio button' in the first column not the checkbox.

Is this a bug?

delete flag offensive retag edit

5 Replies

Sort by ยป oldest newest

answered 2012-08-06 01:21:04 +0800

dennis gravatar image dennis
3679 1 6
http://www.javaworld.com....

updated 2012-08-06 01:23:07 +0800

Could you provide a replay-able viewmodel,
And what is the type of othersModel? if it is a ListModel (not a simple collection), binder will not do extra handling on it, then according to the spec. of ListModel (and Selectable interface), you should setMultiple on it, not use multiple attribute on the component.

link publish delete flag offensive edit

answered 2012-08-06 04:36:15 +0800

itbean gravatar image itbean
9

I encounter the same problem. but i can't get your mean ,could you give an example?

link publish delete flag offensive edit

answered 2012-08-06 04:48:06 +0800

ashishd gravatar image ashishd flag of Taiwan
1972 6

@itbean,
Here is a snippet, in your zul file if you have this

<window title="Order Management" border="normal" width="600px"
	apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('org.zkoss.bind.examples.order.OrderVM')" 
	validationMessages="@id('vmsgs')">
	<vbox hflex="true">
		<listbox model="@load(vm.orders)" selectedItem="@bind(vm.selected)" hflex="true" height="200px" checkmark="true">

Note the checkmark="true" on listbox.

Above if orders is of ListModelList type then you have to call setMultiple(true) on it to turn on the multiple selection. So in your VM

	public ListModelList<Order> getOrders() {
		if (orders == null) {
			//init the list
			orders = new ListModelList<Order>(getService().list());
			orders.setMultiple(true);
		}
		
		return orders;
	}

In above zul code, even if you set multiple="true" on the listbox it wouldn't turn on the multiple selection.

If your model is of generic collection type then ZK binder will automatically wrap it inot a BindingListModel and turn on multiple selection if you have set multiple="true" and checkmark="true" in your zul file.

link publish delete flag offensive edit

answered 2012-08-06 06:00:52 +0800

davout gravatar image davout
1435 3 18

OK, by adding ...

orders.setMultiple(true);

.. to my MVVM code and it now works.

But this does seem a bit like duplicate effort.

link publish delete flag offensive edit

answered 2012-08-06 06:16:12 +0800

itbean gravatar image itbean
9

It works fine. thank you very much.

link publish delete flag offensive edit
Your reply
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

RSS

Stats

Asked: 2012-08-05 13:54:17 +0800

Seen: 280 times

Last updated: Aug 06 '12

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