Tuesday, November 24, 2009

Alfresco Share - helloworld Dashlet

In this blog entry, I will creare a simple HelloWorld(most favorite for all) dashlet in Alfresco Share.

Dashlet is simple component, which makes together dashboard. Dashlet is single Web Script.

To create a dashlet, we need following files from that some files are optional, you may not require in each and every dashlet.

Create all files in the following folder (As per your installation)
C:\Alfresco3.1.2\tomcat\webapps\share\WEB-INF\classes\alfresco\site-webscripts\org\alfresco\components\dashlets

helloworld.get.desc.xml
helloworld.get.js
helloworld.get.html.ftl
helloworld.get.properties

helloworld.get.desc.xml

This is description file of our dashlet which includes display name, description, where you want to put your dashlet, either in user-dashlet family or in site-dashlet family, and url of dashlet. It may include other basics like required authentication, transaction is required or not etc.

<webscript>
   <shortname>Hello World</shortname>
   <description>Hello World Dashlet</description>
   <family>user-dashlet</family>
   <url>/components/dashlets/hello-world</url>
</webscript>


helloworld.get.js

Java script file is to add behavior in the dashlet. It can be used to interact back-end  store. It is optional.
Here, we do not require java script file, but I will show how we can use it.

var name = "niketa";
model.user = name;


helloworld.get.properties

This is our property file, It is also optional

title = Hello World

helloworld.get.html.ftl

This is a freemarker template file. It will render the response.

<div class="dashlet">
  <div class="title">${msg("title")}</div><#-- title’s value will be taken from property file - ->        
  <div class="body scrollableList">
    Hello ${user} <#-- user’s value will be taken from .js file - ->         
  </div>
</div>


To test the dashlet
Go to http://localhost:8080/share/service/index

Click on Refresh Web Scripts

If everything is fine then it will give you following message with number of web script. (Which obviously may differ)

"Maintenance Completed
Reset Web Scripts Registry; registered 179 Web Scripts. Previously, there were 178 "

Login in to your Share (http://localhost:8080/share/)

Click on Customize the dashboard,  ( Add Dashlet,
Here you should find our new dashlet named - Hello World, Add it

And on your dashboard, you will find the message "Hello niketa"