0

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?

5
  • 1
    Are you aware that that javascript is running on the Share server, and not in your browser? Commented Nov 1, 2015 at 19:15
  • I found it to just a few minutes, and I saw that the structure to implement a javascript server-side is different. For example, how can I get the current URL and not through window.location.search? I think for now it was what I needed. Commented Nov 1, 2015 at 19:21
  • @Gagravarr And thank's in advance for that answer. But I have a way to implement the window.location.search ? I can't find this. Commented Nov 1, 2015 at 19:24
  • Why do you need to know the URL? Alfresco needs to know the URL, so it can route control to your JavaScript, but normally you don't need it as you know what URL they wanted as otherwise they wouldn't be on your page! Commented Nov 1, 2015 at 20:08
  • I made a GET in an action button to put some parameters in the query string of URL, so, now, in the new page, I want to get URL to make a parse and get the parameters on the query string url to access the information of the file of the action. How can I make this? Commented Nov 1, 2015 at 20:13

3 Answers 3

2

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!

Sign up to request clarification or add additional context in comments.

4 Comments

I think this can help me, but, I still having problems with this. I have an URL like localhost:8080/share/new-page?file={something} so, I put on the XML <url>/new-page?file={file?}</url> (i don't know if it is correct) and on javascript I have: var fileProp=args["file"] model.temp=fileProp; On FTL file I have: ${temp} to print for page. But I got an error: Exception: freemarker.core.InvalidReferenceException - The following has evaluated to null or missing: ==> temp... You know what is wrong?
The args are printing this : {guid=tmpComponent, url=/new-page, id=tmpComponent, htmlid=global_x002e_share-header_x0023_default} Only args... without args["file"]. The args are not the parameters of query string :S You know why ? :S
My error is in my url. I have like localhost:8080/share/page/hdp/wp/new-page... If I delete /hdp/wp/ it works. Thanks.
There is no need to include the request parameters as tokens in the WebScript descriptor XML file - it will still match the WebScript without them. You should just use the args variable as described by Gagravarr. If you building an Aikau page you shouldn't really need to be changing the FreeMarker (.ftl) file for the page. The only think you need in there is the <@processJsonModel> statement to render the model.jsonModel object built in your WebScript JavaScript controller
2

The JavaScript isn't different, the language itself is still the same.

window, console and alert are just APIs supplied by browsers. They aren't a native part of JavaScript.

The documentation you linked to should be your starting point for figuring how what APIs are available.

2 Comments

Thanks for the answer. I'll explore this. I was a little confused with the server / client. You know how I can get "window.location.search" that we have in browsers, that is, the current URL in this way?
I'm not familiar enough with that API.
0

You can get the server URL in the Javascript web script (on the backend) by

var path = url.getServer()

http://localhost:8080 will be returned for example

Here is the list of available the methods - you can concatenate them to get a direct URL:

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.