Results 1 to 3 of 3

Thread: Sending form values json encoded to REST java webservice

  1. #1
    Sencha User
    Join Date
    Nov 2011
    Posts
    52
    Answers
    2
    Vote Rating
    1
      0  

    Default Sending form values json encoded to REST java webservice

    Hi all,

    I'm new to Sencha Touch and want to build a simple form panel which will be send to a REST service which is implement with Java jersey. The webservice is working properly (tested with Soap UI) and also the sencha app is working fine until I'll press the submit button of the form and if I'm using the submit() function. If I use Ajax in the button handler, the webservice will be called properly, otherwise I get following exception at the webservice:

    Code:
    Caused by: java.lang.Error: Error: could not match input    at 
    com.sun.jersey.json.impl.reader.JsonLexer.zzScanError(JsonLexer.java:491)
        at com.sun.jersey.json.impl.reader.JsonLexer.yylex(JsonLexer.java:736)
    Sencha code:

    Code:
    { 
                               text: 'Save',
                                ui: 'confirm',
                                handler: function() {
                                    console.log('storing');
                                    var form = Ext.getCmp('checkoutform');
                                    console.log(Ext.JSON.encode(form.getValues()));
                                    form.submit({
                                            url: 'http://localhost:8080/example/service/',
                                            method:'POST', 
                                            headers: {
                                                'Content-Type': 'application/json'
                                            },
                                            params: Ext.JSON.encode(form.getValues()),                                    
                                            success:function(form, result){
                                                   console.log("succ");
                                             },
                                              failure:function(form, result){
                                                console.log("fail");
                                            }
                                    });
                                }
                            }
    If i use the following code the call of the webservice is working fine:

    Code:
    {
                                text: 'Save',
                                ui: 'confirm',
                                handler: function() {
                                    console.log('storing');
                                    var form = Ext.getCmp('checkoutform');
                                    console.log(Ext.JSON.encode(form.getValues()));
                                    Ext.Ajax.request({
                                            url: 'http://localhost:8080/example/service/',
                                            method:'POST', 
                                            headers: {
                                                'Content-Type': 'application/json'
                                            },
                                            params: Ext.JSON.encode(form.getValues()),
                                    })
                                }
                            }
    Does anyone have an idea why the form.submit function is sending anything but not properly json data?
    btw. form.getValues() returns json data:

    Code:
    {"name":"","address":""}

  2. #2
    Sencha User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,062
    Answers
    3976
    Vote Rating
    1390
      0  

    Default

    The submit method is going to use form POST and encode the params using Ext.urlDecode.

    If you need a more specialized way of submitting, you can use Ext.Ajax.request to do the submitting. In fact, jsonData will automatically encode the Object to JSON.
    Mitchell Simoens @LikelyMitch
    Modus Create, Senior Frontend Engineer
    ________________
    Need any sort of Ext JS help? Modus Create is here to help!

    Check out my GitHub:
    https://github.com/mitchellsimoens

  3. #3
    Sencha User
    Join Date
    Nov 2011
    Posts
    52
    Answers
    2
    Vote Rating
    1
      0  

    Default

    Hi,

    I thought that

    Code:
    headers: {'Content-Type': 'application/json' }, 
     params: Ext.JSON.encode(form.getValues()),
    would encode the url encoded form data to json encoded data.

    Is it possible to change the encoding format of the form data or do I have to use Ext.Ajax.request instead?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •