1. #1
    Sencha User
    Join Date
    Mar 2007
    Posts
    80
    Vote Rating
    0
    ismoore is on a distinguished road

      0  

    Default ContentPanel.setURL() adds new event listener

    ContentPanel.setURL() adds new event listener


    I hope this is a bug and not something stupid I am doing!
    I have a layout with a grid control and elsewhere several tabs that give different information based on the currently selected row in the grid.

    Therefore I have the following trigger on the selection model:
    ...
    Code:
    	sm.addListener("selectionchange",function(sm){
    				try{
    					msgid=sm.getSelected().id
    					onMsgChange(msgid)
    				}
    				catch(e){}
    				}
    		, ds, true);
    
    ....
    function onMsgChange(msgid){
    	var layout = Bijective.Operations.isNetting? messageDetailLayout: nettingDetailLayout
    	var cp = layout.getRegion('center').getActivePanel()
    	Bijective.Operations.cpmsg.setUrl(Bijective.constants.mvc + "/getMessage", {msgid:msgid,resulttype:'msgdata'})
    	Bijective.Operations.cpaudit.setUrl(Bijective.constants.mvc + "/getMessage", {msgid:msgid,resulttype:'txnaudit'})
        ...				
    	cp.fireEvent("activate")
    
    }
    All of this works fine. A message is selected, the URL parameters are changed, and if there is an active tab, the fire event forces the tab to refresh.

    I started to realise that as the application was used, the performance dropped and this made me notice that there were multiple refreshes in the ContentPanel, one for each row that had been selected.
    So the first time though all would work as expected. The second time, two calls would be made, one with the parameters as per the first row and a second with the new parameters. The third would be similar with a call for all three parameters and so on.
    So Each call to setURL was creating a new listener for onactivate.

    digging deeper into setURL, I found the following:
    Code:
     setUrl : function(url, params, loadOnce){
    	if(this.refreshDelegate){
    		this.removeListener("activate", this.refreshDelegate);
     	}
     	this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
     	this.on("activate", this._handleRefresh.createDelegate(this, [url, params, loadOnce]));
     	return this.el.getUpdateManager();
     },
    It appears that the removeListener does nothing as it does not think the listener exists.
    I think this is because the on() is getting a new delegate and hence the two are not matching
    should it not be:
    Code:
     this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
     this.on("activate", this.refreshDelegate);
    ?

    Just one last point, it would be great to have a method where just the parameters could be changed rather (and existing ones overridden) as I am sure it is more than likely that the URL stays the same but one or more parameters are (re)set.

    Ian
    Last edited by ismoore; 16 May 2007 at 4:50 AM. Reason: sumbitted too soon

  2. #2
    Sencha User
    Join Date
    Mar 2007
    Posts
    80
    Vote Rating
    0
    ismoore is on a distinguished road

      0  

    Default that does work also!

    that does work also!


    Sorry forgot to mentioned that I had tried this and it does fix the problem.

    Quote Originally Posted by ismoore View Post
    should it not be:
    Code:
     this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
     this.on("activate", this.refreshDelegate);
    ?

  3. #3
    Sencha User jack.slocum's Avatar
    Join Date
    Mar 2007
    Location
    Tampa, FL
    Posts
    6,955
    Vote Rating
    17
    jack.slocum will become famous soon enough jack.slocum will become famous soon enough

      0  

    Default


    Thanks for hunting down the solution. That is indeed the problem.

    On a side note, I would recommend using load() instead of setUrl + refresh for multiple loads as it saves the overhead of creating the delegate and adding the listener.
    Jack Slocum
    Ext JS Founder
    Original author of Ext JS 1, 2 & 3.
    Twitter: @jackslocum
    jack@extjs.com

  4. #4
    Sencha User
    Join Date
    Mar 2007
    Posts
    80
    Vote Rating
    0
    ismoore is on a distinguished road

      0  

    Default


    Quote Originally Posted by jack.slocum View Post
    On a side note, I would recommend using load() instead of setUrl + refresh for multiple loads as it saves the overhead of creating the delegate and adding the listener.
    Actually I will probably have to regress the code as previously I was not setting the URL but trapping the onactivate myself and then using load though that seemed to have some other issues which may be related to this problem hence the change. If I regress I will see if I can reproduce the original problems with the modified Ext code.

    If there was an easy way just to change the parameters in this instance that would help.

    The users are a bit slow at clicking so they don't seem to mind too much
    Ian

Thread Participants: 1