Search code examples
javascriptxmlalfrescofreemarkeralfresco-share

Alfresco - Getting the URL from server-side JavaScript


I'm trying to create a new page in Alfresco, but the tutorials gives to me the information that i have to create three files: new-page.get.js, new-page.html.ftl and new-page.get.xml , like Aikau - http://docs.alfresco.com/5.0/concepts/dev-extensions-share-page-creation.html

But the javascript is different, for example, I try to get the current URL with: window.location.search or make console.logor alert. But, in this three cases, I got "undefined" like "window is undefined"

Why is this javascript different? What type of javascript is? Where I can get tutorials, for example, to program this javascripts?

I want to make a window.location.search to get the current URL , but if I don't have this command, what can I use for this effect?


Solution

  • Normally, the Alfresco way wouldn't be to get the raw URL. Instead, you should be using the built-in argument processing

    Since Alfresco itself is open source, we can look at Alfresco for some examples! So, starting with the groups get webscript, we see a URL pattern defined as:

    <url>/api/groups?shortNameFilter={shortNameFilter?}&zone={zone?}&maxItems={maxItems?}&skipCount={skipCount?}&sortBy={sortBy?}</url>
    

    With that, we see a whole bunch of pre-defined parameters on the URL.

    Next, we look at the javascript controller behind that webscript, and we see things like:

    var shortNameFilter = args["shortNameFilter"];
    var zone = args["zone"];
    

    Those URL parameters are then parsed into your webscript in the args variable, available for you to fetch as a hash.

    No need to do any raw URL munging yourself, if you define your webscript correctly the framework does it all for you!