Results 1 to 2 of 2

Thread: send multiple / additional parameters to Jersey configured service method using model

  1. #1
    Sencha User
    Join Date
    Sep 2012
    Posts
    1
    Vote Rating
    0
      0  

    Default Unanswered: send multiple / additional parameters to Jersey configured service method using model

    Hello There,
    I have tried a lot to send additional parameters to Jersey configured service methods from model.save(). extraParams will not work in this case, because we are using DaoHandler (which is not a servlet, but a simple java class) in server side and the model.save() must land to the exact method. But I didn't find any solution in the web and ultimately find a solution of my own. This trick really works for me.

    ----------The Model----------
    Ext.define('MyApp.model.MyTestModel', {
    extend: 'Ext.data.Model',

    fields: [
    {
    name: 'dtoName',
    type: 'string'
    },
    {
    name: 'errorMessage',
    type: 'string'
    },
    {
    name: 'empId',
    type: 'int'
    },
    {
    name: 'accountsList',
    type: 'auto'
    },
    {
    name: 'countryNamesList',
    type: 'auto'
    },
    {
    name: 'accountRecord',
    type: 'auto'
    }
    ],

    proxy: {
    type: 'rest',
    url: 'http://localhost:8888/DirectExtJs/rest/QuickReg/myTestMethod',
    headers: {
    'Content-Type': 'application/json'
    },
    reader: {
    type: 'json'
    }
    }
    });
    --------End of Model----------

    -----Button Click Handler--------
    var myAccountRecord = function (firstName){
    this.firstname = firstName;
    this.lastname = Ext.getCmp('txtAccountLastName').value;
    this.startdate = Ext.getCmp('dtAccountStartDate').value;
    this.accountdesc = Ext.getCmp('txtAccountDescription').value;
    };
    var accountData = new myAccountRecord('SAMUDRANIL');
    var accountData1 = new myAccountRecord('SAMUDRANIL1111');
    var accountData2 = new myAccountRecord('SAMUDRANIL2222');
    var accountData3 = new myAccountRecord('SAMUDRANIL3333');
    var accountData4 = new myAccountRecord('SAMUDRANIL4444');

    var accountList = [accountData1,accountData2,accountData3,accountData4];

    var myTestModel = Ext.create('MyApp.model.MyTestModel');
    myTestModel.set('dtoName', "MyDTO");
    myTestModel.set('errorMessage', "This is a error");
    myTestModel.set('empId', 10);
    myTestModel.set('accountsList', accountList);
    myTestModel.set('accountRecord', accountData);

    var jsonStr = Ext.JSON.encode(accountData);
    var jsonStr2 = Ext.JSON.encode(accountData); //this can be any other object

    var newURL = myTestModel.proxy.url;
    newURL = newURL + '/' + jsonStr + '/' + jsonStr2;
    myTestModel.proxy.url = newURL;

    myTestModel.save({
    success : function(quickRegModel, operation){
    var jsonData = Ext.JSON.decode(operation.response.responseText);
    Ext.Msg.alert('Success', 'Customer Created Successfully');
    console.log(jsonData);
    },
    failure: function(response, operation) {
    console.log(operation);
    alert('Customer Creation Failed.');
    }
    });
    ------End of Button Click Handler------

    -----Service class(DaoHandler)--------
    @Service("QuickRegService")
    @Path("/QuickReg")
    public class JCQuickRegistrationUnicornDAOHandler
    {
    @POST
    @Path("/myTestMethod/{arnab}/{samudra}")
    @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
    @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) // JERSEY
    public static String myTestMethod( MyTestDto testDto, @PathParam("arnab") String mystr, @PathParam("samudra") String yourstr) throws Exception
    {
    Gson gson = new Gson();
    CcAccount acc1 = gson.fromJson(mystr, CcAccount.class);
    CcAccount acc2 = gson.fromJson(yourstr, CcAccount.class);

    testDto.setDtoName("Amar DTO@" + acc1.getFirstname() + "@" + acc2.getLastname());

    String jsonString = gson.toJson(testDto);

    return jsonString;

    }
    }
    -----End of Service class(DaoHandler)--------

    Hope This will help you...............

  2. #2
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,412
    Answers
    3898
    Vote Rating
    1288
      0  

    Default

    Tried passing in params?

    Code:
    record.save({
        params : {
            foo : 'bar'
        }
    });
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it!

    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.

Tags for this Thread

Posting Permissions

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