PDA

View Full Version : How to reach derived components by using original xtype



j-joey
3 Aug 2010, 7:58 AM
I couldn't decide where to write, so wanted to ask here...

It does make sense that when you extend an ext class to have another one, new one will not have an xtype until you register one.

My problem is related to this situation. I have noticed that in my toolbar (which contains separately exported buttongroups that are loaded by users privileges) i couldn't reach to buttongroups by using findByType( 'buttongroup' ) or findByType( Ext.ButtonGroup )

I know, because of my button groups are not instances of ButtonGroup anymore, i cannot reach all of them easily by using findByType.

Now, i'm looking for an elegant way to reach all these components.

Any idea?

jarrednicholls
3 Aug 2010, 10:20 AM
Hey Joey,

Actually, findByType would normally work. Looks like the flaw is in the class hierarchy itself. Your exported ButtonGroup classes are derived from their "Ui" class, which in turn is derived from Ext.ButtonGroup. Because the "Ui" class isn't registering an xtype, the hierarchy chain is broken when doing a lookup.

There are two solutions to this: 1) add a Ext.reg() call for the "Ui" classes to preserve the entire xtype hierarchy, or 2) use the monkey patch code below to make the hierarchy work even if a class "in the middle" didn't register itself:



Ext.override(Ext.Component, {
getXTypes : function(){
var tc = this.constructor;
if(!tc.xtypes){
var c = [], sc = this;
/*while(sc && sc.constructor.xtype){*/
while(sc){
/*c.unshift(sc.constructor.xtype);*/
if (sc.constructor.xtype){
c.unshift(sc.constructor.xtype);
}
sc = sc.constructor.superclass;
}
tc.xtypeChain = c;
tc.xtypes = c.join('/');
}
return tc.xtypes;
}
});


Code in bold are the changes, commented stuff is the original version.

Hope that helps!

j-joey
3 Aug 2010, 12:23 PM
thanks jarred! you've saved the day again :)

monkeypatch is just great! gonna use it...

jarrednicholls
3 Aug 2010, 6:33 PM
No problem! Thanks for your help on the forums as well.