Results 1 to 6 of 6

Thread: Trees can have "unsynchronized" TreeStores ->NullPointers

Threaded View

Previous Post Previous Post   Next Post Next Post
    Success! Looks like we've fixed this one. According to our records the fix was applied for EXTGWT-2430 in 3.0.3.
  1. #1
    Ext GWT Premium Member
    Join Date
    Oct 2007
    Posts
    44
    Vote Rating
    3
      0  

    Default Trees can have "unsynchronized" TreeStores ->NullPointers

    Hi,

    there is a bug in Tree(Panel)s caused by unsynchronized Stores. If a Tree is given a TreeStore it adds handlers to listen to store events. For example an added entry in the store causes the tree to register a new node. Certain events, however, can cause the store and tree to become unsynchronized. Examples are:
    • Filtering
    • Loading store data before giving the store to the tree
    • Probably more


    If now an update on the store occurs, the tree's onUpdate method is called:
    Code:
      protected void onUpdate(StoreUpdateEvent<M> event) {
        for (M item : event.getItems()) {
          TreeNode<M> node = findNode(item);
          if (node.model != item) {
            node.model = item;
          }
          refresh(item);
        }
      }
    Here the tree assumes that a node corresponding to the updated StoreModel exists. However, due to the two not being completely synched, this may not be the case. In this case findNode(item) return null and the whole thing produces a NullPointerException:

    Code:
    Caused by: java.lang.NullPointerException
    	at com.sencha.gxt.widget.core.client.tree.Tree$TreeNode.access$1(Tree.java:345)
    	at com.sencha.gxt.widget.core.client.tree.Tree.onUpdate(Tree.java:1864)
    	at com.sencha.gxt.widget.core.client.tree.Tree$Handler.onUpdate(Tree.java:510)
    	at com.sencha.gxt.data.shared.event.StoreUpdateEvent.dispatch(StoreUpdateEvent.java:101)
    	at com.sencha.gxt.data.shared.event.StoreUpdateEvent.dispatch(StoreUpdateEvent.java:1)
    	at com.google.gwt.event.shared.GwtEvent.dispatch(GwtEvent.java:1)
    	at com.google.web.bindery.event.shared.EventBus.dispatchEvent(EventBus.java:40)
    	at com.google.web.bindery.event.shared.SimpleEventBus.doFire(SimpleEventBus.java:193)
    	at com.google.web.bindery.event.shared.SimpleEventBus.fireEvent(SimpleEventBus.java:88)
    	at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:127)
    	... 40 more
    A temporary bugfix is to override the onUpdate method with the following:
    Code:
    	protected void onUpdate(StoreUpdateEvent<M> event) {
    		for (M item : event.getItems()) {
    			TreeNode<M> node = findNode(item);
    			if(null == node)
    				register(item);
    		}
    		super.onUpdate(event);
    	}
    This causes the missing nodes first to be registered and then "updated".
    Last edited by acerberus; 3 Aug 2012 at 2:19 AM. Reason: typo

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •