AnsweredAssumed Answered

How to get content coming back from a repository javaback webscript in share JS?

Question asked by vince20151 on Aug 21, 2013
Latest reply on Aug 21, 2013 by vince20151
I'm working on a very simple exercise to create a Java webscript in Alfresco. It extends DeclarativeWebScript and returns a simple string. I can call this webscript on the URL and it works.
On the share side, I have a JS file that calls the web script via remote.connect.
This is where I am stuck. How do I get the content from the remote call and put it in the model. It seems to fail at the eval statement and my free marker renders this string org.mozilla.javascript.Undefined@12fa845 instead of the string returned from remote.
Any advice is appreciated.

Here is the JS on the share side
function main() {
  var connector = remote.connect("alfresco");
  var result = connector.get("/alfresco/service/aa/simpleremote");
 
  if (result.status == status.STATUS_OK)
  {
    data = eval("(" + result.response + ")");
  }
  model.html = result["html"];
}
main();


Here is the Java code on the repository side
public class SimpleWebScriptModel extends DeclarativeWebScript {
   protected Map<String, Object> executeImpl(WebScriptRequest req,
          Status status, Cache cache)   {
      Map<String, Object> model = new HashMap<String, Object>();
      String myString = "Hello World";
      model.put("html", myString);
      return model;
   }
}

Outcomes