1. #1
    Sencha Premium Member
    Join Date
    Dec 2011
    Posts
    23
    Vote Rating
    1
    ipavlic is on a distinguished road

      0  

    Default Answered: Form submit POST request JSON data

    Answered: Form submit POST request JSON data


    How can I POST JSON data when submitting a form; or alternatively, how can I POST JSON data from a form (without calling submit)?

    When form like
    Code:
    
    var basicInfo = new Ext.form.FormPanel({ 
        ...     api: { 
            ... 
            submit: profile.updateBasicInfo     } 
      });
    is submitted with
    Code:
    basicInfo.getForm().submit();
    The POST request header has a application/x-www-form-urlencoded content-type and the request body is urlencoded.

    I would like it to be a JSON request (having an application/json content type in the header and jsonData in the request body). The reason that I would like a JSON request is that the parameters are currently not deserialized correctly by Spring.

    For illustration, let's say I have a MyValueObject and a MyOtherValueObject
    Code:
    MyValueObject {
        private String parameterOne;
        private List<MyOtherValueObject> myList;
        ... //getters, setters
    }
    
    MyOtherValueObject{
        private String otherParameter;
        //getters, setters
    }
    The list of MyOtherValueObjects is not properly deserialized when it is urlencoded with Ext.Object.toQueryString(myList). JSON encoding just the list is also not being properly deserialized.

  2. If you take a look at the docs for Ext.form.Basic, you can actually submit a form using an ajax config. For example:

    PHP Code:
    basicInfo.getForm().submit({
        
    url'/service/YourSpringService',
        
    method'POST',
        
    params: {
            
    additionalParam1'test'
        
    },
        
    success: function(formaction) {
            
    Ext.Msg.alert('Success'action.result.msg);
        }
    }); 
    You could also assign a handler to a Save button in the form too and just do a standard ajax post.

    PHP Code:
    this.saveBtn.on('click'this.onSubmitFormthis);

    ...

    onSubmitForm: function() {
        
    Ext.Ajax.request({
            
    method'POST',
            
    url'/service/YourSpringService',
            
    params: {
                
    // your params go here
            
    },
            
    success: function() {
                ...
            }
        });

        ...


  3. #2
    Sencha User
    Join Date
    Jan 2008
    Location
    CA
    Posts
    47
    Answers
    1
    Vote Rating
    0
    Ant1105 is on a distinguished road

      0  

    Default


    If you take a look at the docs for Ext.form.Basic, you can actually submit a form using an ajax config. For example:

    PHP Code:
    basicInfo.getForm().submit({
        
    url'/service/YourSpringService',
        
    method'POST',
        
    params: {
            
    additionalParam1'test'
        
    },
        
    success: function(formaction) {
            
    Ext.Msg.alert('Success'action.result.msg);
        }
    }); 
    You could also assign a handler to a Save button in the form too and just do a standard ajax post.

    PHP Code:
    this.saveBtn.on('click'this.onSubmitFormthis);

    ...

    onSubmitForm: function() {
        
    Ext.Ajax.request({
            
    method'POST',
            
    url'/service/YourSpringService',
            
    params: {
                
    // your params go here
            
    },
            
    success: function() {
                ...
            }
        });

        ...


  4. #3
    Sencha Premium Member
    Join Date
    Dec 2011
    Posts
    23
    Vote Rating
    1
    ipavlic is on a distinguished road

      0  

    Default


    I guess that answers my question. Thanks!

Thread Participants: 1