-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Dear colleagues,
I am working on a complex form with a rather large view model and we have several tabs for different parts and in particular we have a distinct model underlying each tab. Nevertheless, there is a "base" view model class called "StructureMapping" that underlies the form. (The actual class names are not of importance here, but only included to make it a bit less abstract).
This StructureMapping references a list of "hierarchy attributes" (see figure) and depending on which hierarchy attribute is selected in that list, another list is depicted that shows "attribute mappings" for that hierarchy attribute. Now, each list supports the following operations: - add an element below the selected - remove the selected element - move up / down the selected element Each list is accompanied by a set of buttons to perform these actions. The activation-state of the button of course changes depending on the contents of the list and the selected item. For instance, I cannot move up the top item, I cannot remove an item if none is selected, etc. So depending on the operations we want to update the button states.
Now the issue is, we have a component (we call it list operator) that encapsulates such lists because we have various lists of this type in our system. So, the button states are not just boolean properties of the view model but of an object referenced by the view model.
Here is an example of a move-up button
<button id="mButtonMoveUpAttributeMapping"
image="/img/tn-arrow-up.png"
tooltiptext="${labels.tooltip.lists.moveUpSelected}"
sclass="tn-btn-gray rounded tn-arrow-up"
onClick="@command('moveUpAttributeMapping')"
disabled="@load(not vm.attributeMappingListOperator.isMoveUpAllowed or not vm.isConnected)">
Now, we want to update the state of the button, for instance, when an element is moved up. So we annotate the command with @NotifyChange ...:
@NotifyChange( "attributeMappingListOperator.isMoveUpAllowed" )
@Command public void moveUpAttributeMapping() { mMappingListOperator.moveUpSelection(); }
But this just doesn't work (as you can see in the figure where the move-up button is active although the top mapping is selected). The event is not properly interpreted and the button's state is not properly updated.
What am I doing wrong here?
Thanks beforehand, David
I've experienced something to the issue you are reporting, and I think it has something to do with the way ZK handles the message queue.
My issue related to changing list box item positions using up/down/top/bottom buttons and the code just didn't work. So I introduced a mechanism where the event handler in the view model class did not make the list changes itself. Instead the event handler posted a global change event on the message queue to access another VM class method where the changes were made.
In the pseudo code below my 'moveUpAttributeMapping' method is the event handler reacting to your button click event. This event handler pushes a message that ends up calling 'executeMoveUp' which does implement the list model changes.
public class MyVM {
private final static String GLOBAL_COMMAND_EXECUTE_MOVE_UP_ATTRIBUTE = "xxxx";
@Command("moveUpAttributeMapping")
public void moveUpAttributeMapping() {
// push a method onto the message queue that will
BindUtils.postGlobalCommand(QUEUE_NAME,
QUEUE_SCOPE,
GLOBAL_COMMAND_EXECUTE_MOVE_UP_ATTRIBUTE,
null);
}
@GlobalCommand(GLOBAL_COMMAND_EXECUTE_MOVE_UP_ATTRIBUTE)
@NotifyChange({"listmodel","selectedListItem","buttonToDisabled"})
public void executeMoveUp() {
// insert here the code to change the list positions
}
}
Hope this helps.
Hi Davout,
no, I fear that doesn't really help me. My problem was that I have actually a nested view model which is a part of the "whole"-viewmodel in the sense that it is one of its properties. But unfortunately, events and properties of view models do not extend through the object graph. What I need is some support of this expression: @NotifyChange( "attributeMappingListOperator.isMoveUpAllowed" )
As a remark: In your example, I think the problem may be that your global command now causes a complete reset of the list model. So now it looks as if it works, but in fact you are just rerendering the whole page on each operation. Could that be the case?
Cheers, David
Asked: 2013-06-11 08:30:47 +0800
Seen: 36 times
Last updated: Jun 21 '13
Databinding and auto-complete on combobox
Composite component and bind in ZK 6
How to detach / reattach MVVM windows?
Is there a way to resolve view model properties as input to client side javascripts?
How can I synchronize data in a ListBox in MVVM ? [closed]
MVVM Validator: class not found ? [closed]
How to Call Child ViewModel Method from Parent Window? [closed]
have this same problem will be thankful for help.
veronicahudson ( 2013-06-12 18:24:29 +0800 )edit