cancel
Showing results for 
Search instead for 
Did you mean: 

Alfresco.util.Ajax.request with POST request not sending the request data to Javabacked webscript in Alfresco 5.0.c.

abhinav
Champ on-the-rise
Champ on-the-rise
Hi all,
I was using Alfresco 5.0.a community for developing dashlets and java backed webscipts. Alfresco.util.Ajax.request with POST was working fine in 5.0.a. But when i upgraded to Alfresco 5.0.C, it stopped working. Parameters sent in dataObj ( as given below ) are not reaching to the java backed webscript, i am getting the null values from WebScriptRequest (request) object. Where in Alfresco 5.0.a its working fine.

         (
             dataObj: {
      breadcrumb : selectedBreadcrumb,
      id: id,
      format : "html"
            }
    )

JavaWebscript:
public class DashletAction extends DeclarativeWebScript {

@Override
protected Map<String, Object> executeImpl(final WebScriptRequest request,
         final Status status, final Cache cache) {

  cache.setNeverCache(true);
  // Retrieve and validate parameters
  final String breadcrumb = request.getParameter("breadcrumb"); //GETTING NULL here in Alfresco 5.0.c
  final String id = request.getParameter("id"); //GETTING NULL here in Alfresco 5.0.c
  final String format = request.getParameter("html"); //GETTING NULL here in Alfresco 5.0.c

  //……DO Something with these parameters

}
}

Ajax call from .ftl File:

function onDashletAction(obj){
        var scriptURL = Alfresco.constants.PROXY_URI+"component/data-integration/dashlet-action;
   var selectedID = document.getElementById(obj.id).value.split("|");
   INPUTNAME =  obj.name; // Set the input name to global INPUTNAME variable.
   var breadcrumbId = selectedID[0];
   var id=selectedID[1];
   var selectedBreadcrumb = document.getElementById(breadcrumbId).value;   
    
   Alfresco.util.Ajax.request({
     url: scriptURL,
     method: Alfresco.util.Ajax.POST,
     timeout:200000,
     dataObj: {
      breadcrumb : selectedBreadcrumb,
      id: id,
      format : "html"
     },
     successMessage: "Successfully retrieved the Hierarchy.",
     successCallback: {
      fn: this.handleSuccess,
      scope: this
     },
     failureMessage: "Failed to retrieved the Hierarchy!",
     failureCallback: {
      fn: this.handleFailure,
      scope: this
     },
     execScripts: true
   });
}
2 REPLIES 2

s_palyukh
Star Contributor
Star Contributor
mmm, This code can't be working in Alfresco 5.0.a if you do a POST request…

You try to get information from request parameters, but it is in the request body.

Try to do the following:


Content content = req.getContent();

        // get request content (should be JSON string)
        String params = content.getContent();

try {
            // parse string params to JSON object
            JSONObject jsonObject = new JSONObject(params);

            // get breadcrumb
            String breadcrumb = jsonObject.getString("breadcrumb");

} catch (JSONException e) {

            throw new AlfrescoRuntimeException("Request doesn't contain json object. " + e.getMessage());
}

abhinav
Champ on-the-rise
Champ on-the-rise
Hi Palyukh

Above code which i mentioned above is working fine in Alfresco 5.0.a when i reverted back to older version from 5.0.c.

Again i upgraded to 5.0.c and I was getting exception while trying to use the above mentioned code by you .

Error message: "Request doesn't contain json object. A JSONObject text must begin with '{' at character 0"

But problem was resolved when i added 'requestContentType: Alfresco.util.Ajax.JSON' in the ajax call.


Thank you for help Smiley Happy