1. #1
    Sencha User
    Join Date
    Sep 2012
    Posts
    1
    Vote Rating
    0
    samu_dra_nil is on a distinguished road

      0  

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

    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 - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    St. Louis, MO
    Posts
    33,684
    Vote Rating
    435
    Answers
    3111
    mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of

      0  

    Default


    Tried passing in params?

    Code:
    record.save({
        params : {
            foo : 'bar'
        }
    });
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    http://www.JSONPLint.com - Source to lint your JSONP!

    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 almost in print!

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