0

Nested models

asked 2013-06-11 08:30:47 +0800

avidD gravatar image avidD
166 2

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).

image description

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

delete flag offensive retag edit

Comments

have this same problem will be thankful for help.

veronicahudson ( 2013-06-12 18:24:29 +0800 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2013-06-13 08:03:14 +0800

davout gravatar image davout
1435 3 18

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.

link publish delete flag offensive edit
0

answered 2013-06-21 07:31:37 +0800

avidD gravatar image avidD
166 2

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

link publish delete flag offensive edit

Comments

It might well cause a full refresh - I'm not sure that the ZK MVVM model supports the update of individual rows in a grid or listbox

davout ( 2013-07-01 21:10:19 +0800 )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
3 followers

RSS

Stats

Asked: 2013-06-11 08:30:47 +0800

Seen: 36 times

Last updated: Jun 21 '13

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