1. #1
    Sencha Premium Member
    Join Date
    May 2010
    Location
    Guatemala, Central America
    Posts
    1,310
    Vote Rating
    112
    ssamayoa is just really nice ssamayoa is just really nice ssamayoa is just really nice ssamayoa is just really nice ssamayoa is just really nice

      0  

    Default Can I override Store's constructor or component's initComponent()?

    Can I override Store's constructor or component's initComponent()?


    I just updated my Designer to build 309. Apart for some minor glitches is working and there is the new feature to create override class.

    Can I override Store's constructor or component's initComponent()?

    I need to populate some store with a list of years like:

    Code:
    Ext.define('AutoGestion.store.override.Anos', {
        requires: 'AutoGestion.store.Anos'
    }, function() {
        Ext.override(AutoGestion.store.Anos, {
            constructor : function(cfg) {
                cfg.data = [{ano: 2007, nombre: '2007'}];
                this.callOverridden(cfg);
            }
        });
        alert("override1");
    });
    But new constructor code isnt invoked...

    Some example please...

    Regards.
    UI: Sencha Architect 3.x / ExtJS 4 & 5
    Server side: JEE / EJB 3.x / CDI / JPA 2.x/ JAX-RS / JasperReports
    Application Server: Glassfish / WildFly
    Databases: Oracle / DB2 / MySQL / Firebird

    If you like my answer please vote!

  2. #2
    Sencha - Architect Dev Team aconran's Avatar
    Join Date
    Mar 2007
    Posts
    9,365
    Vote Rating
    128
    aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold

      0  

    Default


    This works fine in Sencha Touch 2.0.0. There is a bug in Sencha Touch 2 < Beta 3 that causes the override to not be loaded before the application launches.

    It appears the same bug also appears in 4.0.2a. Will investigate further what it takes to fix this in Ext JS 4.0.x.
    Aaron Conran
    @aconran
    Sencha Architect Development Team

  3. #3
    Sencha Premium Member
    Join Date
    May 2010
    Location
    Guatemala, Central America
    Posts
    1,310
    Vote Rating
    112
    ssamayoa is just really nice ssamayoa is just really nice ssamayoa is just really nice ssamayoa is just really nice ssamayoa is just really nice

      0  

    Default


    Quote Originally Posted by aconran View Post
    It appears the same bug also appears in 4.0.2a.
    FWIW I replaced 4.0.2a with 4.0.7 in my application and got the same result.

    I'm using Chrome 16.0.912.63 m in Windows 7.

    Regards.
    UI: Sencha Architect 3.x / ExtJS 4 & 5
    Server side: JEE / EJB 3.x / CDI / JPA 2.x/ JAX-RS / JasperReports
    Application Server: Glassfish / WildFly
    Databases: Oracle / DB2 / MySQL / Firebird

    If you like my answer please vote!

  4. #4
    Sencha Premium Member
    Join Date
    May 2010
    Location
    Guatemala, Central America
    Posts
    1,310
    Vote Rating
    112
    ssamayoa is just really nice ssamayoa is just really nice ssamayoa is just really nice ssamayoa is just really nice ssamayoa is just really nice

      0  

    Default


    UPDATE:
    overriding initComponent() works!

    Overriding constructor() doesn't.

    Both tested with Ext 4.0.7.

    Regards.
    UI: Sencha Architect 3.x / ExtJS 4 & 5
    Server side: JEE / EJB 3.x / CDI / JPA 2.x/ JAX-RS / JasperReports
    Application Server: Glassfish / WildFly
    Databases: Oracle / DB2 / MySQL / Firebird

    If you like my answer please vote!

  5. #5
    Sencha - Architect Dev Team aconran's Avatar
    Join Date
    Mar 2007
    Posts
    9,365
    Vote Rating
    128
    aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold

      0  

    Default


    We're aware of the problems with Ext JS and are working to address them.

    This technique works fine in Touch.
    Aaron Conran
    @aconran
    Sencha Architect Development Team

  6. #6
    Sencha Premium Member
    Join Date
    May 2010
    Location
    Guatemala, Central America
    Posts
    1,310
    Vote Rating
    112
    ssamayoa is just really nice ssamayoa is just really nice ssamayoa is just really nice ssamayoa is just really nice ssamayoa is just really nice

      0  

    Default


    Quote Originally Posted by aconran View Post
    We're aware of the problems with Ext JS and are working to address them.

    This technique works fine in Touch.
    Yep, you already said that.

    I tried a different approach for "year combo": I wrote a custom component overriding initComponent() + some custom properties so the final result was better: YearComboBox component which I can use anywhere in my application. I also wrote a MonthComboBox (which I need in several views in my application) thanks for the override mechanism.

    That problem (constructor override) forced me to think different and the final result was better.

    Regards.
    UI: Sencha Architect 3.x / ExtJS 4 & 5
    Server side: JEE / EJB 3.x / CDI / JPA 2.x/ JAX-RS / JasperReports
    Application Server: Glassfish / WildFly
    Databases: Oracle / DB2 / MySQL / Firebird

    If you like my answer please vote!

  7. #7
    Sencha Premium Member
    Join Date
    Dec 2011
    Location
    London, UK
    Posts
    260
    Vote Rating
    8
    bseddon will become famous soon enough

      0  

    Default


    I may be missing the specificity of your scenario however overloading a store constructor when using 4.0.7 works in my case. Here's an example I'm using right now in order to be able to apply a url resolved through the use of a function, something which is not permitted in the designer:

    Code:
    Ext.define('Photos.store.override.Images', {    requires: 'Photos.store.Images'
    }, function() {
        Ext.override(Photos.store.Images, {
            constructor: function(cfg)
            {
    			console.log(Ext.String.format('Images: {0}', Ext.photosThumbService));
    			this.callOverridden(cfg);
    			this.getProxy().url = Ext.photosThumbService;
            }
        });
    });
    A difference is that I'm grabbing the proxy after it's been assigned by the super's constructor and then changing the url. Maybe a similar approach (setting the data variable explicitly rather than via config settings) would work for you?

  8. #8
    Sencha Premium Member
    Join Date
    May 2010
    Location
    Guatemala, Central America
    Posts
    1,310
    Vote Rating
    112
    ssamayoa is just really nice ssamayoa is just really nice ssamayoa is just really nice ssamayoa is just really nice ssamayoa is just really nice

      0  

    Default


    Quote Originally Posted by bseddon View Post
    Maybe a similar approach (setting the data variable explicitly rather than via config settings) would work for you?
    Nope.
    The problem I have is that the overriden constructor is never called.
    I tried with 4.0.1, 4.0.2 and 4.0.7.

    I throwed the code and used a different approach (creating the store in component's initComponent() method) but definitely I will give a try later.

    Regards.
    UI: Sencha Architect 3.x / ExtJS 4 & 5
    Server side: JEE / EJB 3.x / CDI / JPA 2.x/ JAX-RS / JasperReports
    Application Server: Glassfish / WildFly
    Databases: Oracle / DB2 / MySQL / Firebird

    If you like my answer please vote!

  9. #9
    Ext JS Premium Member corcoranp's Avatar
    Join Date
    Apr 2007
    Location
    Pleasant Grove, AL
    Posts
    25
    Vote Rating
    3
    corcoranp is on a distinguished road

      0  

    Default Same issue

    Same issue


    I've run into the same issue. I have a store for which I already have data for and wanted to set the data property before the store gets a concrete implementation. I ran down the issue, and it's all about timing.

    Basically, the store that I'm overloading is referenced in a view that is creating the store BEFORE, the overload is is applied.

    I'm using:
    Sencha Designer Version 2.0.0 Build: 309 RC: 2.0-beta
    with
    Ext 4.0.7

    I've been able resolve this by editing the Designer generated code after deployment, but that's been a bit of a pain. I'm going to try overloading the initComponent and see if I get a different result! Thanks!

    It would be nice if you could set properties of an object in the designer to a user-defined variable...

    Cheers!

    BTW...I think this is my first post since Jack owned this...
    Peter M Corcoran

    ExtJs Developer since 2007
    www.corcoranp.com
    http://www.linkedin.com/in/corcoranp

  10. #10
    Sencha Premium Member
    Join Date
    May 2010
    Location
    Guatemala, Central America
    Posts
    1,310
    Vote Rating
    112
    ssamayoa is just really nice ssamayoa is just really nice ssamayoa is just really nice ssamayoa is just really nice ssamayoa is just really nice

      0  

    Default


    Quote Originally Posted by corcoranp View Post
    I've run into the same issue. I have a store for which I already have data for and wanted to set the data property before the store gets a concrete implementation. I ran down the issue, and it's all about timing.
    Oh!

    That explains the odd behaviour.

    Thanks for the information.
    UI: Sencha Architect 3.x / ExtJS 4 & 5
    Server side: JEE / EJB 3.x / CDI / JPA 2.x/ JAX-RS / JasperReports
    Application Server: Glassfish / WildFly
    Databases: Oracle / DB2 / MySQL / Firebird

    If you like my answer please vote!