Wednesday, July 29, 2009

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

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-INF folder.

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.
<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!