/* InfoAxon GA Code */
Alfresco One: Content Management in the Cloud (Part II)
December 18, 2012 – 1:55 pm | No Comment

Alfresco Universe has a number of client applications and protocols available which can be used by your external users making this a truly Cloud Content Enterprise Content Management System.
For example,

Alfresco iOS Client App: for iPhone …

Read the full story »
Home » Open Source Tutorials

Tutorial: Building Alfresco web scripts, deploying as Liferay Portlets – Part 4

Submitted bySnig Bhaumik on October 4, 2009 – 5:50 am5 Comments

Deploying the Web Scripts as Liferay Portlets

Well, we now are able to create and build web scripts both by Java and by JavaScript.
Now, we want our web scripts to be displayed in Liferay portal as portlets.

For that, we need to update the following xml files in order to register the alfresco web scripts in Liferay portlet list. These files are in C:\mystackroot\webapps\alfresco\WEB-INFfolder.

For deploying the Alfresco web scripts in Liferay, you need to add the information of the web script (as portlet) in 4 XML files, restart your server, and Whoa – you are done.

web.xml
  • Register the Web Script as a servlet.
<servlet>
<servlet-name>myfirstscript</servlet-name>
<servlet-class>com.liferay.portal.kernel.servlet.PortletServlet</servlet-class>
<init-param>
<param-name>portlet-class</param-name>
<param-value>org.alfresco.web.scripts.portlet.WebScriptPortlet</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
  • Register the Servlet mapping.
 Mirrors dvd
<servlet-mapping>
<servlet-name>myfirstscript</servlet-name>
<url-pattern>/myfirstscript/*</url-pattern>
</servlet-mapping>
  • In this way, register all the web scripts as servlets to be deployed as Liferay portlets.
  • portlet.xml

    Register the web scripts as portlets

    <portlet>
    <description>myfirstscript</description>
    <portlet-name>myfirstscript</portlet-name>
    <portlet-class>org.alfresco.web.scripts.portlet.WebScriptPortlet</portlet-class>
    <init-param>
    <name>authenticator</name>
    <value>webscripts.authenticator.jsr168.webclient</value>
    </init-param>
    <init-param>
    <name>scriptUrl</name>
    <value>/alfresco/168s/infoaxon/repository/ myfirstscript</value>
    </init-param>
    <supports>
    <mime-type>text/html</mime-type>
    <portlet-mode>VIEW</portlet-mode>
    </supports>
    <portlet-info>
    <title>My First Web Script</title>
    <short-title>My First Web Script</short-title>
    </portlet-info>
    </portlet>
    

    Few points to be noted here:

    1. portlet-name should match the web script name
    2. scriptURL should be like /alfresco/168s/<<web-script-url-as-defined-description-xml>>

    In this way, register all the web scripts to be deployed as Liferay portlets.

    liferay-portlet.xml

    Define the web scripts as portlets

    <portlet>
    <portlet-name>myfirstscript</portlet-name>
    <use-default-template>true</use-default-template>
    <restore-current-view>true</restore-current-view>
    </portlet>
    
    • The portlet-name must be same as defined in portlet.xml file.
    • In this way, define all the web scripts to be deployed as Liferay portlets.
    liferay-display.xml

    Describe how the portlets will be displayed in Liferay portlet list
    <portlet id=”myfirstscript”></portlet>

    The portlet id should match the portlet-name defined earlier.
    You can define your own category in which you would like see your portlets in Liferay.

    <display>
    <category name="My Custom Portlets">
    <portlet id="myfirstscript"></portlet>
    <portlet id="helloworld"></portlet>
    </category>
    </display>
    

    In this way, define all the web scripts to be deployed as Liferay portlets.

    Congrats, All Done!!!
    • Restart your server.
    • Navigate to Liferay and login as a user with suitable permissions to add a portlet is a page.
    • Open the Add Application popup in liferay. You should see My Custom Portlets category in the list and the portlets you have just registered under it.
    • Drag your portlet in the page and enjoy!

    About The Author

    Snig Bhaumik

    Mr. Snigdhendu Bikas Bhaumik is the Technical Director and Heads the Research and Development for InfoAxon. As an Open Source enthusiast, Snig is an active contributor of several open source communities such as - Alfresco ECM (Author of Alfresco Calendar components now included and distributed in Alfresco version 3.0), Liferay Portal and Pentaho Business Intelligence Suite. Snig has just completed a book on Alfresco published by Packtpub - http://www.packtpub.com/alfresco-3-cookbook/book. Snig specializes in Knowledge Management and Business Intelligence domains, and responsible for designing and architecting InfoAxon’s KM and BI solution offerings. He holds an enriching experience of around 12 years in designing, architecting and developing various solutions on open source technologies. Follow him on twitter - @snigbb.

    5 Comments »

    • [...] Web Scripts as Portlets tutorials, how to deploy Alfresco Web Scripts as Liferay Portlets have been discussed. In this [...]

    • nikolai says:

      Hello everybody,

      I have a Tomcat server with a Liferay Portal (6.0.5) and Alfresco (v3.4c). I followed some tutorials to have webscripts as portlets, and everything seems to work well with out-of-the-box UI portlet.

      But, I have a problem with my own webscripts, especially when I have:
      - a webscript with a form
      form.get.html.ftl:

      Code: Select all

      Name :
      File :

      - a webscript with the formdata object to catch informations from the previous webscript
      form.post.js:

      Code: Select all
      var filename = null;
      var content = null;
      var title = “”;

      // locate file attributes
      for each (field in formdata.fields)
      {
      if (field.name == “name”)
      {
      title = field.value;
      }
      else if (field.name == “myfile” && field.isFile)
      {
      filename = field.filename;
      content = field.content;
      }
      }
      // treatment….

      My problems:
      - When I press the submit button, I leave the portal. I found a solution with the scripturl() method

      Code: Select all

      - But POST webscripts don’t seem to be supported by the WebScriptPortlet class. A first solution was to bring together the both webscripts.

      Code: Select all

      Code: Select all
      if (args.step == 1)
      {
      //treatment with the formdata object
      }
      else
      {
      //treatment to build the form
      }
      - But now, I have this exception when I submit the form: Exception: org.mozilla.javascript.EcmaError – ReferenceError: “formdata” is not defined (AlfrescoScript#10)

      Is there an issue with POST webscripts in portlet? Is there a solution to my problem?

      Thank you, and excuse me for my english

    • Snig Bhaumik says:

      Hi Nikolai

      I am assuming you are invoking the 2nd web script as the post action of the form in your 1st web script.
      In addition to that, the form in your 1st web script should have some special attributes such as
      method="post" enctype="multipart/form-data"

      Thus form tag would look like
      <form id="frmUploadDoc" method="post" enctype="multipart/form-data" accept-charset="utf-8" action="/alfresco/service/.....">

      I understand your problem that you are being redirected from the portal while submitting the form. For that I normally open a little new browser window and force my form (from 1st web script) to submit to the new window.
      Adding this, the form tag will be
      <form id="frmUploadDoc" target="newwin" method="post" enctype="multipart/form-data" accept-charset="utf-8" action="/alfresco/service/.....">

      Hope this helps.

      Snig.

    • Carlo says:

      Hi i’m trying to use a webscript as portlet, using your guide. But i can’t understand, how liferay, can comunicate with Alfresco,

      i have Liferay 6.1 on a Machine, and Alfresco 3.4 on an other machine… i think that Liferay need and Url to get the webscript/portlet..

      Can you explain this point?

      thank you..!!

    • Snig Bhaumik says:

      Hi Carlo

      The first pre-requisite of this model is that Liferay and Alfresco should be deployed in a single App Server, needless to say in a single machine. Similar in case of clustered setup also.

      However, if your deployment is having two different machines, then you have to use something like WSRP portlets in Liferay. The above approach won’t work.

      Hope this helps.
      Snig.

    Leave a comment!

    Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

    Be nice. Keep it clean. Stay on topic. No spam.

    You can use these tags:
    <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

    This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.