[CLOSED] Manually loading controls

  1. #1

    [CLOSED] Manually loading controls

    Some days ago i started a thread regarding the load of controls during view creation:
    http://forums.ext.net/showthread.php...-View-creation

    but after updating from SVN, my code stopped working. After analysing ComponentLoader implemetation, i noticed that it was due a new functionality of ComponentLoader, that registers controls' resources on ResourceManager.

    To overcome the problem, i had to implement docReady function as shown bellow:

    1 - View
    <script runat="server">
        public void Page_Load(object sender, EventArgs e)
        {
            ResourceManager.RegisterControlResources<SelectBox>();
        }
    </script>
    <!DOCTYPE html>
    <html>
    <head runat="server">
        <title>Index</title>
        <script type="text/javascript">
            var docReady = function () {
    
                var decoded = Ext.decode(App._hddContent.value);
    
                if (decoded.config != null) {
                    decoded = Ext.decode(decoded.config);
                }
    
                App._pnlContainer.add(decoded);
    
                App._hddContent.destroy();
            }
        </script>
    </head>
    <body>
        <ext:ResourceManager ID="ResourceManager1" runat="server">
            <Listeners>
                <DocumentReady Handler="docReady();" />
            </Listeners>
        </ext:ResourceManager>
        <ext:Panel ID="_pnlContainer" TitleCollapse="true" Border="false" runat="server" />
        <ext:Hidden ID="_hddContent" Width="400" Text="<%# ViewBag.DynamicContent %>" AutoDataBind="true"
            runat="server" />
    </body>
    </html>
    2 - View Creation
    public ActionResult Index()
    {
        Panel pnlControls = new Panel();
    
        pnlControls.Items.Add(new Button());
    
        //pnlControls.Items.Add(new SelectBox());
    
        ViewBag.DynamicContent = ComponentLoader.ToConfig(pnlControls);
    
        return View();
    }

    App._hddContent.value when the View Creation line 7 is commented
    [{
        xtype: "panel",
        items: [{
            xtype: "button"
        }]
    }]
    App._hddContent.value when the View Creation line 7 is uncommented
    {
        'x.res': {
            res: [{
                url: "/ux/selectbox/selectbox-js/ext.axd?v=18148"
            }]
        },
        config: "[{xtype:\"panel\",items:[{xtype:\"button\"},{xtype:\"selectbox\",queryMode:\"local\",triggerAction:\"all\",store:Ext.data.StoreManager.getArrayStore(2)}]}]"
    }
    But i would like to take the advantage of new ComponentLoader implementation, that registers controls' resources, so i copied ComponentLoader implementation and adapted to my scneario, as shown bellow:

    3 - New Javascript code
    <script type="text/javascript">
        var docReady = function () {
    
            var decoded = processContent(App._hddContent.value);
    
            App._pnlContainer.add(decoded);
    
            App._hddContent.destroy();
        }
    
        var processContent = function (resp) {
            if (Ext.isObject(resp)) {
                cfg = resp;
            }
            else if (Ext.isString(resp)) {
                cfg = Ext.decode(resp, true);
                resp = cfg;
            }
            else {
                cfg = null;
            }
    
            if (cfg && cfg['x.res']) {
                if (cfg['x.res'].ns) {
                    Ext.ns.apply(Ext, cfg['x.res'].ns);
                }
    
                if (cfg.config) {
                    resp = Ext.decode(cfg.config, true);
                }
    
                if (cfg['x.res'].res) {
                    Ext.net.ResourceMgr.load(cfg['x.res'].res);
                }
            }
            return resp;
        }
    </script>
    But if i remove View lines 1 to 6 (shown bellow), an is exception is thrown during namespaceRewrites.
    <script runat="server">
        public void Page_Load(object sender, EventArgs e)
        {
            ResourceManager.RegisterControlResources<SelectBox>();
        }
    </script>
    I think my code dic not act properly on New Javascript code line 33, in other words, it was not able to register controls' resources.

    Any ideas to overcome this issue?
    Last edited by Daniil; Nov 20, 2012 at 12:35 PM. Reason: [CLOSED]
  2. #2
    Hi Raphael,

    Well, the resources are loaded asynchronously. So, you have to load the components in a callback.

    Example
    Ext.net.ResourceMgr.load(cfg['x.res'].res, function () {
        App._pnlContainer.add(resp);
        App._hddContent.destroy();
    });
  3. #3
    Thank you Daniil, i will apply your solution to my scneario and be sure that i will keep you posted once i retest the application.
  4. #4
    Daniil, it worked like a charm. Please mark this thread as closed.

Similar Threads

  1. [CLOSED] Loading controls on View creation.
    By RCN in forum 2.x Legacy Premium Help
    Replies: 5
    Last Post: Nov 12, 2012, 10:50 AM
  2. Viewport and dynamic loading controls
    By TheAlchemistBR in forum 1.x Help
    Replies: 2
    Last Post: Jan 19, 2012, 1:29 PM
  3. Replies: 0
    Last Post: Jan 05, 2011, 6:48 AM
  4. [CLOSED] Dynamic loading of user controls [1.0]
    By SFritsche in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Feb 11, 2010, 6:08 AM
  5. [CLOSED] [1.0] Loading controls dynamicly ?
    By klavsm in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Dec 14, 2009, 6:29 AM

Posting Permissions