Friday, January 9, 2009

Tutorial: Building Alfresco web scripts, deploying as Liferay Portlets - Part 2

Creating a Web Script using JavaScript API

Step 1: Define the Web Script
As you know, to define a web script, we need to have:
  1. A description xml file, in our case the name would be helloworld.get.desc.xml
  2. An FTL file generating HTML code, in our case the name would be helloworld.get.html.ftl
  3. A JS file, in our case the name would be helloworld.get.js. Note that, this JS is technically not mandatory; however, in practical situation you cannot live without this, because this is only place where you write the business logic of your web script, and return some data.
These files need to be created in C:\mystackroot\webapps\alfresco\WEB-INF\classes\alfresco\templates\webscripts\ folder hierarchy.
  • Create subfolder hierarchy com\infoaxon\repository under C:\mystackroot\webapps\alfresco\WEB-INF\classes\alfresco\templates\webscripts\ folder.
  • Note that, maintaining this folder hierarchy is not mandatory; this is just because of good practice to group your web scripts. Technically as per alfresco, it will pick up all items which are defined as web scripts under the templates\webscripts\ folder.
  • Under the repository folder, create the following three files:


helloworld.get.desc.xml
<webscript>
<shortname>helloworld</shortname>
<description>helloworld</description>
<url>/infoaxon/helloworld</url>
</webscript>

helloworld.get.html.ftl
<html>
<body>
<p>Wow, this is quite ${jstext}, rather.</p>
</body>
</html>

helloworld.get.js
model.jstext = "Simple";

Step 2: Start Server, Test your Web Script
That’s it, that’s really it, you have just created your first JavaScript based custom web script.
  • Start tomcat server
  • In your favourite browser, navigate to http://localhost:8080/alfresco/service/index. Find your web script and test whether it is working, but just clicking on it.
  • Since, you have created a HTTP GET Web Script, you can invoke and test the service by typing URL in your browser http://localhost:8080/alfresco/service/infoaxon/helloworld. Note that, this is the URL which you have defined in your configuration XML file.
In the next installment of this tutorial, we will discuss about how we can create a simple helloworld web script using java.

1 comment:

  1. how to process forms in webscript. When submit button is clicked We will leave liferay portal.What do we need to do for staying in current portal.Thanks!

    ReplyDelete