Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    DMI.call with parameters into servlet -- cannot get params into servlet

    Hello,

    This is not a bug, I am just missing the knowledge on how to do it, I spend lots of hours on it without any good result.
    Help. Thanks.

    1. smartgwt 3.1 and smartclient 8.3p

    2. firefox, chrome etc.

    I am trying to get the variables from a javascript request made from smartclient to a servlet in a smartgwt (DMI.call), I cannot get the parameters in a format I can use... I don't know how to do it.


    This calls directly to the servlet successfully. I tested it without having a requirement in the servlet and it works.
    Smartclient code in javascript
    Code:
    var data = { customer_id: "10"};
    isc.DMI.call({            
    	    appID: "builtinapp",
                className: "com.whatever.printCustomer",            
                methodName: "doGetPDF", 
                requestParams: {                
                    actionURL: "/builtinapp/builtinapp/sc/IDACall",      
                    containsCredentials: true,           
                    downloadResult: true,         
                    data: data,
                    downloadToNewWindow: true, 
                },
                 params: ["customer_id", "10"]
                });
    smartgwt servlet
    Code:
    public class printCustomer extends HttpServlet
    {
        private static final long serialVersionUID = -879266760993744323L;
        public void doGetPDF (RPCManager manager, HttpServletResponse response) throws Exception
                {
    
    manager.doCustomResponse();
    
    System.out.println(manager.getRequest().getRequestContext().request.getParameterMap().get("customer_id").toString());
    
    
    }
    error got from log file

    Code:
    === 2013-05-20 23:41:01,074 [ec-1] DEBUG RPCManager - Request #1 (RPCRequest) data: {
        appID:"builtinapp",
        className:"com.whatever.printCustomer",
        methodName:"doGetPDF",
        params:[
            "customer_id",
            "10"
        ],
        arguments:[
        ],
        is_ISC_RPC_DMI:true
    }
    === 2013-05-20 23:41:01,074 [ec-1] INFO  IDACall - Performing 1 operation(s)
    === 2013-05-20 23:41:01,075 [ec-1] DEBUG RPCDMI - appConfig: isc.Application.create({
        rpcBindings:[
            {
                ID:"printCustomer",
                className:"com.whatever.printCustomer",
                visibleMethods:[
                    {
                        name:"doGetPDF"
                    }
                ]
            }
        ]
    })
    
    ...
    === 2013-05-20 23:41:01,075 [ec-1] DEBUG RPCDMI - Invocation threw exception
    java.lang.NullPointerException

    As said above, I want to get some parameters from the javascript layer into the servlet layer through the DMI.call.
    ie.

    I want to pass the customer_id to the servlet so that it prints out only the customer with the ID ie. 10

    I am also interested to know how I can manipulate the JSON into Java objects or strings ie.

    {some_record: { id: 1, name: "whatever", custom: true} } into a List or Map.

    I am not an expert in Java.

    #2
    "params" should be specified as an Object not an Array.

    { customer_id : 10 }

    Comment


      #3
      error log
      Code:
       methodName:"doGetPDF",
          params:[
              {
                  customer_id:"10"
              }
          ],
          arguments:[
          ],
      ...
      
      === 2013-05-21 08:29:37,323 [ec-5] DEBUG RPCDMI - Invocation threw exception
      java.lang.NullPointerException
      servlet
      Code:
      		System.out.println(manager.getRequest().getRequestContext().request.getParameterMap().get("customer_id").toString());

      javascript
      Code:
      var data = { customer_id: "10"};
      isc.DMI.call({            
      	    appID: "builtinapp",
                  className: "com.whatever.printCustomer",            
                  methodName: "doGetPDF", 
                  requestParams: {                
                      actionURL: "/builtinapp/builtinapp/sc/IDACall",      
                      containsCredentials: true,           
                      downloadResult: true,         
                      data: data,
                      downloadToNewWindow: true, 
                  },
                   params: [data]
                  });

      Can Isomorphic be more specific on the servlet commands that read from params?

      Comment


        #4
        Still wrong, now you are passing an Array with one Object in it, get rid of the hard brackets ("[").

        Comment


          #5
          I can manage with one or two vars passed but, I would like to pass a record or json object. How can I do that?

          Comment


            #6
            One thing - this is the Smart GWT forum, but you appear to be working directly in JavaScript so are presumably working with straight SmartClient. If this is not correct, let us know!

            ---
            The docs for DMI.call are here.

            Firstly note that if you're passing in this format (a single parameter object with properties set to specify appID, className, callback etc), the property name for the arguments array is arguments rather than params.

            These arguments should be passed to your server method automatically. There is an automatic conversion from JavaScript objects to Java. See the docs for RPCRequest.data for an overview of how the conversion from JavaScript to Java behaves.
            If you also need to look at the arguments outside your method, by analyzing the incoming RPCRequest object on the server, you can use the getMethodArguments() API.


            Regards
            Isomorphic Software

            Comment


              #7
              hello,

              Thanks for your reply, I tried it and it worked for what I wanted to do.

              this is the code for reference:

              servlet
              Code:
                      List methodargu = manager.getRequest().getMethodArguments();
                   
                      //size of the passed arguments
                      System.out.print(methodargu.size());
                   
                      //get first object passed in arguments
                      // {customer_id: 0}
                      Map mData = (Map) methodargu.get(0);
               
                      //customer_id: 0
                      //ie. get the customer_id from the arguments thing       
                      Integer customerID = mData.get("customer_id");
              javascript from smartclient
              Code:
              var data = { customer_id: "10"};
              isc.DMI.call({            
              	    appID: "builtinapp",
                          className: "com.whatever.printCustomer",            
                          methodName: "doGetPDF", 
                          requestParams: {                
                              actionURL: "/builtinapp/builtinapp/sc/IDACall",      
                              containsCredentials: true,           
                              downloadResult: true,         
                              downloadToNewWindow: true, 
                          },
                           arguments: [data]
                          });
              The reason that I wanted this is to use jasper reports with Smartclient, we are using a combination of the both, SmartGWT, Smartclient in our applications.

              Comment


                #8
                DMI call for jasper reports

                Thanks, i think that i found what i need but i couldnt't work it out. I need to call my servlet class to print a jasper report.

                My app already has been using smartclient into js files to client side.

                I use an adaptation of RPCManager to call an ActionHandler class when i clicked a button, so it really work fine. But now i need to call a servlet to print a Jaspereport, so i tried with DMI.call funct, but i recieve tha IDACalll resource is not found (http 404 error).

                Could u help me please?

                Comment


                  #9
                  I think you should enter the correct path to IDACALL. ie.
                  actionURL: "/builtinapp/builtinapp/sc/IDACall",

                  where builtinapp is the name of your application as defined in the server.properties file.

                  Comment

                  Working...
                  X