3 Replies Latest reply on Nov 15, 2012 4:04 PM by Nitin Khare

    Invoking FormHandler handle method using REST Framework

      We are calling OOTB CartModifierFormHandler's handleSetOrderByCommerceId method using REST framework. This method get the quantity for each commerceItem from the request and is not mapped to a property of the formhandler. How should the quantity for each commerceItemId be passed for this handle method as a parameter? We are using ATG 10.0.3
        • 1. Re: Invoking FormHandler handle method using REST Framework
          Nitin Khare
          When invoking through REST, the form handler parameters can be passed using the parameters argument which is of Map type where key will be the parameter name and value will be the parameter value that you want to pass. So for calling CartModifierFormHandler.handleSetOrderByCommerceId() and to pass the quantity for each commerceItemId in your order you can try to do something like this:
          Map<String,String> params = new HashMap<String,String>();
          List items = order.getCommerceItems();  //here order is your Order object with which you would be working
          for(int i= 0; i<items.size(); i++)
            CommerceItem item = (CommerceItem)items.get(i);
            String commerceItemId = item.getId();
            String quantity = getQuantityForCommerceItemId();  //get the quantity for this commerceItemId 
            params.put(commerceItemId, quantity);
          RestResult result = RestComponentHelper.executeMethod("/atg/commerce/order/purchase/CartModifierFormHandler", "setOrderByCommerceId", null, params, session);
          • 2. Re: Invoking FormHandler handle method using REST Framework
            Nitin, Has it worked for you? We tried the same, but its not working. In the FH handle method, when getQuantity method is invoked,its not getting the value, we printed the entire request object, but don't see the commerItemId (actual id) parameter. Seems like the REST framework only sets the value that is mapped to FH property not to request.
            • 3. Re: Invoking FormHandler handle method using REST Framework
              Nitin Khare
              I have not tried this myself but it should work. The parameters provided would always be added to the underlying http request and therefore values should be available through reques.getParameter() within the formhandler. Check if there is no possible name conflict in the parameters being added as it could cause the dropping of that parameter from the http request. To test this you can also try with some hard coded parameter and retrieve its value within the extended formhandler. Also, you can try to monitor the http request that your REST client would be making to the ATG server and see if you can track the "Content-Type" header having value as "application/x-www-form-urlencoded" along with the POST data. If all this doesn't give any clue then as an alternative probably you can try with json/xml based input and see if that makes any difference.