0

Creating a Dual Listbox component for MVVM application

asked 2015-06-17 09:46:27 +0800

WilliamB gravatar image WilliamB
1609 1 6

updated 2015-06-17 10:48:46 +0800

Found that great exemple : http://www.zkoss.org/zkdemo/listbox/dual_listbox

Copy & pasted the code and after a little cleaning I've a custom component that i can reuse easily on my zul

<duallistbox model="@load(vm.listEntityAvailableForGroup)" chosenDataList="@save(vm.entity.listEntityToAddToGroup)"/>

Now my only issue is what do I need to add to the DualistBox.java file of my component so when the user click on one of the button, on top of moving the item, it also triggers the @save ?

Thanks for your help

delete flag offensive retag edit

1 Answer

Sort by » oldest newest most voted
0

answered 2015-06-17 10:48:31 +0800

WilliamB gravatar image WilliamB
1609 1 6

updated 2015-06-17 11:48:26 +0800

Sharing since i found out how to do it.

You gotta use the @ComponentAnnotation annotation like described : http://books.zkoss.org/wiki/ZK_Developer%27s_Reference/MVVM/Advanced/Binding_Annotation_for_a_Custom_Component (http://books.zkoss.org/wiki/ZKDeveloper%27sReference/MVVM/Advanced/BindingAnnotationforaCustom_Component)

In DualListbox, I added the annotation on my getter :

@ComponentAnnotation("@ZKBIND(ACCESS=save, SAVE_EVENT=onChoose)")
public List<String> getChosenDataList() {
    return new ArrayList<String>(chosenDataModel);
}

And then you only need to make sure you send the "onChoose" event when you click on the buttons.

Events.postEvent(new ChooseEvent(this, set));

In the ZK exemple it's already the case for the onChoose & unchooseItem methods. So you only need to make it so that the chooseAllItem & unchooseAll also send this event and voilà.


Btw am I right in thinking that in the current use case, there is no use for the data attribut of the ChooseEvent object?

It's just in case someone want to intercept it to see what is getting changed right?

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: 2015-06-17 09:46:27 +0800

Seen: 24 times

Last updated: Jun 17 '15

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