PDA

View Full Version : Extending a Super Class and making it reusable



pleuraxeraphim
26 Feb 2012, 4:28 AM
Hi

I want to create a resuable class like below. (Note: I stripped out all the extra fields for simplicity)
But basically in different parts of the aplication I will want to Ext.extend the TestPanel class as below.
I want to then change the properties for example of the TextField with id of : 'adviceInstructions.line1',

So I will want to change maybe whats in the value field to be '${structure2.TotalAmount}', and maybe readOnly : false.

How do I extend this class as is and reference certain parts of that class so I can change them.
I have tried this and I cannot get this to work.
Hope this make sense.



var TestPanel = Ext.extend ( Ext.Panel, {

initComponent:function() {

Ext.apply(this, {

labelAlign : 'top',
labelSeparator : '',
layout : 'form',
border : false,
items : [
{
id : 'adviceInstructions.line1',
name : 'adviceInstructions.line1',
xtype : 'textfield',
readOnly : true,
value : '${structure.TotalAmount}',
hideLabel : 'true',
anchor : '95%'
} ],
anchor : '76%',
fieldLabel : '<spring:message code="application.fieldTotal"/>',
padding : '5 0 0 0',

});

TestPanel .superclass.initComponent.apply(this, arguments);
this.addEvents('load');
}
});

mitchellsimoens
27 Feb 2012, 5:37 AM
You don't. You will need to modify the base class to use some properties to configure itself.

pleuraxeraphim
27 Feb 2012, 6:39 AM
Hey Thanks for the reply. As I am new to Ext-JS I am a bit confused.

Maybe I am approaching this incorrectly so. I want to be able to set different values for that the textfields in that base class (TestPanel) depending on where it it used in the application. That class would be used in several places but will have different message populating the text fields.

So when I subclass a class in ext-js then I can only add stuff to it but not change the behaviour of the underlying base class ?

Sorry for stupid question :) I am approaching this as a Java programmer.

pleuraxeraphim
27 Feb 2012, 8:00 AM
So am I correct in assuming that the 'items' are a f
ixed array of components that are not exposed as attributes and therefore cannot be changed by an extending subclass ?

mitchellsimoens
28 Feb 2012, 6:29 AM
It can be changed after it is created however the items array isn't a simple array after you do the superclass call.