Drag and Drop with MVVM

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">
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 retag edit

10 Replies

hawk
2630 1 5
http://hawkphoenix.blogsp...

Hi,

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

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


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.

hawk
2630 1 5
http://hawkphoenix.blogsp...

Hi,

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

rickcr
704 7

@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 ?

hawk
2630 1 5
http://hawkphoenix.blogsp...

Hi,
Do you use ZK EE 6.0.1 ?

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>


rickcr
704 7
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>


hawk
2630 1 5
http://hawkphoenix.blogsp...

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

BonnieBIG
3

This is very useful for me !Thank you!

Mirabelleter
3

could you provide a sample for reproduce it ?

[hide preview]