0

Drag and Drop with MVVM

asked 2012-05-21 16:07:36 +0800

mannelletto gravatar image mannelletto
6

HI,
i'm trying use drag and drop with a listbox in MVVM.
The ListBox is following:

<listbox model="@bind(vm.example)" >
<template name="model">
<listitem draggable="true" droppable="true" label="@load(each.example.displayName)" attributes.item="@load(each)"
onDrop="@command('moveExample', item=event.dragged.attributes.item, base=each)" />
</template>
</listbox>

and in the relative java file there is method:

@Command
public void moveExample(@BindingParam("base") ExampleType base,
@BindingParam("item") ExampleType item) {
/* Something */
}

my problem is that in the moveExample the ExampleType item is always null.

delete flag offensive retag edit

10 Replies

Sort by ยป oldest newest

answered 2012-05-30 03:57:06 +0800

hawk gravatar image hawk
2335 1 5
http://hawkphoenix.blogsp... ZK Team

Hi,

I think event.dragged is the listitem you want to drag.

@command('moveExample', item=event.dragged, base=each)

link publish delete flag offensive edit

answered 2012-06-07 15:21:33 +0800

rickcr gravatar image rickcr
704 7

Have you got this working, I'm having the same issue handling this in a ModelView as well.

<listbox id="userSelectionsList" width="350px"  multiple="true"
model="@bind(vm.productGroupComponents)" selectedItems="@bind(vm.productGroupComponentsSelected)"
onDrop="@command('onCharacteristicDropped', item=event.dragged)" droppable="true">
	 
</listbox>

In my MV

@Command
public void onCharacteristicDropped(@BindingParam("item") Object item) {
	logger.debug("On Characteristic Dropped item: {}", item); 
}

Item is always null? Ideally eventually I want to get the actual java object backing the item in the zk list, but for now I'm just trying to get access to anything that is dragged.

link publish delete flag offensive edit

answered 2012-06-08 01:25:45 +0800

hawk gravatar image hawk
2335 1 5
http://hawkphoenix.blogsp... ZK Team

Hi,

according to http://books.zkoss.org/wiki/ZK_Developer%27s_Reference/MVVM/Advance/Parameters#Retrieve_Event_Object

After 6.0.1 you can use implicit variable "event" in command binding.

link publish delete flag offensive edit

answered 2012-06-08 03:47:25 +0800

rickcr gravatar image rickcr
704 7

updated 2012-06-08 03:47:48 +0800

@Hawk... but according to that same doc I should be able to just pass the param in the command like I showed above? onDrop="@command('onCharacteristicDropped', item=event.dragged)"
Unless I'm missing something, I shouldn't have to get the event with @ContextParam in my VM ?

link publish delete flag offensive edit

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

hawk gravatar image hawk
2335 1 5
http://hawkphoenix.blogsp... ZK Team

Hi,
Do you use ZK EE 6.0.1 ?

link publish delete flag offensive edit

answered 2012-06-08 13:00:32 +0800

rickcr gravatar image rickcr
704 7

I'm using 6.0.1 but wasn't using the EE version so I switched to that but still not having much luck... is there a dependency I'm missing in my pom?

         <properties>
		<maven.build.timestamp.format>MM.dd.yyyy.HH:mm</maven.build.timestamp.format>
		<zk.version>6.0.1</zk.version> 
		<zkspring.version>3.0</zkspring.version>
	</properties>

		<dependency>
			<groupId>org.zkoss.zk</groupId>
			<artifactId>zkspring-core</artifactId>
			<version>${zkspring.version}</version>
		</dependency>
		<dependency>
			<groupId>org.zkoss.zk</groupId>
			<artifactId>zkspring-webflow</artifactId>
			<version>${zkspring.version}</version>
		</dependency>
		<dependency>
			<groupId>org.zkoss.zk</groupId>
			<artifactId>zkplus</artifactId>
			<version>${zk.version}</version>
		</dependency>
		<dependency>
			<groupId>org.zkoss.zk</groupId>
			<artifactId>zhtml</artifactId>
			<version>${zk.version}</version>
		</dependency>
		<dependency>
			<groupId>org.zkoss.zk</groupId>
			<artifactId>zkbind</artifactId>
			<version>${zk.version}</version>
		</dependency>

Using this repo to pull from

<repository>
			<id>ZK EE</id>
			<url>https://maven.zkoss.org/repo/zk/ee</url>
</repository>

link publish delete flag offensive edit

answered 2012-06-08 16:45:54 +0800

rickcr gravatar image rickcr
704 7

updated 2012-06-08 16:46:31 +0800

I managed to be able to get the event passed to the command using the EE eval repo and including the zkmax dependency (I didn't have that listed above.) Does this mean one has to purchase the EE license in order to accomplish drag and drop in the standard MVVM architecture? This seems somewhat limiting for what I'd think should be a pretty standard UI feature. (Not trying to complain, was just curious. ZK is a great product so worth purchasing, just want to make sure my understanding is correct.)
<repository>
     <id>ZK PE/EE Evaluation</id>
     <url>http://mavensync.zkoss.org/eval/</url>
   </repository>
               <dependency>
		  <groupId>org.zkoss.zk</groupId>
		  <artifactId>zkmax</artifactId>
		  <version>6.0.1</version>
		</dependency>
link publish delete flag offensive edit

answered 2012-07-26 09:57:36 +0800

hawk gravatar image hawk
2335 1 5
http://hawkphoenix.blogsp... ZK Team

Hi,
implicit variable "event" in data binding only supports after 6.0.1 EE .

link publish delete flag offensive edit

answered 2012-07-31 04:16:29 +0800

BonnieBIG gravatar image BonnieBIG
3

This is very useful for me !Thank you!

link publish delete flag offensive edit

answered 2012-08-02 09:06:50 +0800

Mirabelleter gravatar image Mirabelleter
3

could you provide a sample for reproduce it ?

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-05-21 16:07:36 +0800

Seen: 830 times

Last updated: Aug 02 '12

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