cancel
Showing results for 
Search instead for 
Did you mean: 

How to call alfresco java webscript from share

vince20151
Champ in-the-making
Champ in-the-making
Would appreciate code example of a java (not Javascript) webscript controller in share calling an alfresco webscript.
With JavaScript controller in Share, you would use the remote object and make the call like  
  var connector = remote.connect("alfresco");
  var result = connector.call("<Alfresco webscript URI>");

How can I do this for a java backed webscript from share? What is the equivalent java class for the JavaScript "remote" object and how to get it from the implemented method
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) in share.

Thanks a bunch.
6 REPLIES 6

kaynezhang
World-Class Innovator
World-Class Innovator
You have several options:
1.You can delcare a property of org.springframework.extensions.surf.WebFrameworkServiceRegistry(for example serviceRegistry) in your java webscript and inject spring bean with id "webframework.service.registry" to it, Then use following statement you can get an instance of class org.springframework.extensions.webscripts.ScriptRemote ,which is a equivalent of javascript connector.
ScriptRemote scriptRemote = serviceRegistry.getScriptRemote();
2. You can directlry inject spring bean of "org.springframework.extensions.webscripts.ScriptRemote" into your java webscript,spring bean if of "org.springframework.extensions.webscripts.ScriptRemote"  is "webframework.webscripts.scriptremote".
3.Don't use any connector,just use apache commons httpclient to connect to data webscript.

resco
Champ in-the-making
Champ in-the-making
I made Java Backed Webscript which call :

http://localhost:8080/alfresco/s/someco/example/moveCategory?sourceNodeRef=workspace://SpacesStore/3...

Now I've created a new page that has a button and I want to click a button call the above-mentioned WebScript. Event clicking the button calls the function onSearchClick from .js (YUI) of the file, and it should call WebScript but do not know how. Do you have any idea how to do that ?

onSearchClick: function Search_onSearchClick(e, obj)
      {
        
           //Here I would like to invite WebScript


      }, 

rjohnson
Star Contributor
Star Contributor
I'm your webscript looks like a GET so you use an AJAX call inside your event handler which would look something like


                      var me = this;
            var actionUrl = Alfresco.constants.PROXY_URI +
                        "someco/example/moveCategory?sourceNodeRef=workspace://SpacesStore/31005cf4-f4a3-456b-bc06-37e077c39649&targetNodeRef=workspace://SpacesStore/b09d5311-34cc-414a-b1e7-d108eb7ec45a";
            Alfresco.util.Ajax.request(
                      {
                          url: actionUrl,
                          method: Alfresco.util.Ajax.GET,
                          responseContentType: Alfresco.util.Ajax.JSON,
                          successCallback:
                          {
                             fn: me._successHandler,
                              scope: me
                          },
                          failureCallback:
                          {
                              fn: me.__failureHandler,
                              scope: me
                          },
                          scope: me,
                          noReloadOnAuthFailure: me
                     });                

alf_ecm
Champ in-the-making
Champ in-the-making
I have a ajax GET request that returns me JSON data. How can I access this data in javascript funtion _successHandler?

Thanks

resco
Champ in-the-making
Champ in-the-making
Thank you,  this work fine. But now, I do not know how to take the value, inside my event handler(onSearchClick), returned by Java Backed WebScript.



Java Backed is:

public class CustomSearch extends DeclarativeWebScript
{

private java.util.List<Node> sortedNodes;

@Override
   protected Map<String, Object> executeImpl(WebScriptRequest req, Status status)
   {
      
    String   searchTerms = (String) req.getParameter(PARAM_SEARCH_TERMS);
    String   title = (String) req.getParameter(PARAM_TITLE);
    String   description= (String) req.getParameter(PARAM_DESCRIPTION);
      startSearch(searchTerms, title, description);   //this function set sortedNodes
      
      // set up the model
      Map<String, Object> model = new HashMap<String, Object>();
      model.put("sortedNodes", sortedNodes);
      
      return model;

   }

public void startSearch(String searchTerms,String title,String description){
………………
………………
………………
}

}

zladuric
Champ on-the-rise
Champ on-the-rise
So your onSearchClick gets this sortedNodes array, right? What does your FTL for that custom search webscript look like?

I'm guessing your onSearchClick(e, obj) gets this list somewhere?

What do you get in console when you
console.log(arguments)
at the beginning of onSearchClick JS method?