1. #1
    Sencha User
    Join Date
    Jan 2013
    Posts
    1
    Vote Rating
    0
    mattex83 is on a distinguished road

      0  

    Default MVC Form submit changes to the server using direct proxy

    Hi to all,

    I'm developing an extjs application using MVC pattern.
    I have a form with a store defined like this

    Code:
    // The new DataWriter component.
    var writer = new Ext.data.JsonWriter({
                encode : false
            });
    
    
    Ext.define('AM.store.nwkview.NwkPanel1', {
                extend : 'Ext.data.DirectStore',
                requires : 'Ext.direct.*', // use ext-direct for binding
                /**
                 * The model of the data of the store
                 */
                model : 'AM.model.nwkview.NwkPanel1',
    
    
                autoLoad : true,
    
    
                constructor : function(config) {
                    config = config || {};
                    config.proxy = {
                        /* Accept direct methods */
                        type : 'direct',
                        extraParams: {'networkId':0},
                        paramOrder:['networkId'],
                        /* API interface */
                        api : {
    
    
                            read : NetworkView.getPanel1,
                            update : NetworkView.updateNwkConfig
                            // destroy : undefined
                        },
                        /* The reader and the writer */
                        reader : {
                            type : 'json',
                            root : 'result'
                        },
                        writer : writer,
                        paramsAsHash : false
                    };
    
    
                    this.callParent([config]);
                },
                
                load : function(record) {
                               ....
                               ....
                }
            });
    Now, Is it possible to call the store update function from the component's controller to submit it to the server side?
    This is the way I found in some documents across the web but store.sync() won't call the server method specified:

    Code:
              init : function() {
            console.log('init function in panel Controller has been called... ');
            this.control({
                'editpanel[store="nwkview.NwkPanel1"] >> tool[type="save"]' : {
                    click : function(th, e, eOpts) {
                        var store = this.getStore("nwkview.NwkPanel1");
                        debugger
                        store.sync();
                    }
                }
    
    
            });
        }
    My server method is the following:
    Code:
    @DirectFormPostMethod
        public void updateNwkConfig(Map<String, String> formParameters, 
      Map<String, FileItem> fileFields) throws Exception {
            
            WebContext context = WebContextManager.get();
            if(context==null)
                Utils.ERROR_WEBCONTEXT_NULL("Network View", "updateNwkLabel");
    
                  log.info("CALLED!");
    I tried also:

    Code:
    @DirectMethod
        public void updateNwkConfig(JsonElement newlabel) throws Exception {
            
            WebContext context = WebContextManager.get();
            if(context==null)
                Utils.ERROR_WEBCONTEXT_NULL("Network View", "updateNwkLabel");
    
                   log.info("CALLED!");
    }
    but this won't work too

    Any suggestions?

    Thanks for your help.

    M

  2. #2
    Sencha - Senior Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    38,215
    Vote Rating
    1044
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default

    The sync method is the correct means. Is there any actual changes in the store to send?
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

Thread Participants: 1

Tags for this Thread