Sunday, November 16, 2008

How to create a custom dashlet in Alfresco

On this post, I'll try to put in a simple example on creating a hello dashlet.
I'm using a standalone Alfresco (apache tomcat included).

Step by step on creating dashlet in Alfresco :
  1. Create a freemarker template for the dashlet and name it filename.html.ftl (e.g. hello.html.ftl). For freemarker syntax please see http://freemarker.org/. Sample content :
  2. <#assign name = person.properties.userName>
    Hello ${name}
  3. Save the file in tomcat\webapps\alfresco\WEB-INF\classes\alfresco\templates\, you could also a directory inside and put your file in your directory.
  4. Create a jsp file that will include the template file created on step 1. The content of the jsp file would be :
  5. <%@ taglib uri="/WEB-INF/repo.tld" prefix="r" %>

    <%-- Note that this template is loaded from the classpath --%>
    <r:template template="/alfresco/templates/hello.html.ftl">
    </r:template>

  6. Save the jsp file in tomcat\webapps\alfresco\jsp\dashboards\dashlets.
  7. Open web-client-config.xml, you can find it in tomcat\webapps\alfresco\WEB-INF\classes\alfresco.
  8. Register the new dashlet, find "dashlets" (without quotes) in web-client-config.xml, add the following configuration :
  9. <dashlet id="hello" label="Hello Dashlet"
    description="My Hello Dashlet"
    jsp="/jsp/dashboards/dashlets/hello.jsp">
    </dashlet>
  10. To see the new dashlet in action, just restart alfresco, login, configure the dashboard and pick the new dashlet.

That's all the steps for creating a simple dashlet, the key lies on the free marker template (besides the configuration), you could put almost anything over there to render anything you want (of course as long as it's possible :)

23 comments:

Lekseich said...

Great article, she is very useful for me.
How long you use Alfresco?

Santoso said...

I've been looking at developing/extending alfresco for one month, Alfresco documentation is somehow seems to be incomplete (or maybe a clear example will help).

Anonymous said...

Thank you so much Santosa. This could really help.

Joe

Unknown said...

Santoso,

Your r:template is malformed, it should read:

<r:template templatePath="/alfresco/templates/hello.html.ftl">
</r:template>

(or should it be the template="" attribute, I don't know, but you've obviously forgotten an attribute name, whichever it is)

Santoso said...

Fixed! Thanks a lot for the input.

sukumar said...

hey santoso,

i tried it..but im not able to get it.. can u please help me out with this. I'm totally new to alfresco so its taking me some time to get this..

I dont know anything about freemarker actually.. I have used it before..

Can I email u about my problem?..
here is my email please drop in a mail incase u think its ok for me to email u about the trouble im facing with alfresco..

sukumar.pant@gmai.com

aawartan.org said...

You gave me a headstart on Dashlets Santoso! Thanks much. Alfresco is open and free but needs documentation for sure.

Sandy said...

hi santos ,
i am using alfresco 3.2 community edition as i new to alfresco. My problem is i am not able to create web forms or web projects. As created sample as gave in alfresco people.
Please help me what are i need to do to create project . I tried project is creating while launching it giving problem. What are all file required to launch site in alfresco.If u could give any examples it would be very helpful.. i am waiting for your reply. Thanks in advance.

Custom Papers Writing said...

Many institutions limit access to their online information. Making this information available will be an asset to all.

Sandy said...

Hi santosa,
please clear somethings, give some examples.waiting for your reply.

Santoso said...

Hi Sandeep,


Sorry I can't help you. I never tried launching a site in alfresco up to now.

Santoso said...

Hi Sandy,


What kind of example that you need?

Unknown said...

Hi Santoso,
Thanks for the article.
Do you parhaps have one that explains how to add a dashlet to alfresco share?
This would really help

varun said...

hello,
i m developing a knowledge management tool using alfresco community edition3.3.
i implemented an already built dashlet i.e tag cloud bt i want to knw the way to build a dashlet showing the that WHICH TAG IS PROVIDED BY WHICH USER.
as there is already a dashlet which shows that which file is modified or uploaded by which user but it should also show the that which user has provided which tag.

please provide me the solution urgently.

thanks
varun

i m confused said...

hey...Santoso

thanx for such a nice post...

but i need help for using services of alfresco....so if you know that then i request you to put another post about services which will help many developers who uses alfresco.

Regards
Tapan Thakkar

Santoso said...

Hi,

I'm sory, I'm a bit busy at the moment. I'm not sure if I can promise to put another post. But I'll try when I've free time.

Pivert said...

Hi,

No sure why, but the dashlet do not appear in the available dashlets, and nothing in catalina.out. Where should I look for a useful debug output ?

Anonymous said...

I'm having the same problem as the prev post. It's not registering the dashlet this way.

Anonymous said...

Hi,

This tutorial is really helped me in creating. But when I configure it to my dashboard, It's getting configured but at the top of the dashlet its giving me ${documentList-dashlet_title}. How can I set that property.

please send me an e-mail regarding this manish_ranga87@yahoo.com

Regards
Manish

Anonymous said...

Me also, i am really thankful man!

Anonymous said...

In addition to the comment of Thomas, i would like to add something to save other's time.

in the file: web-client-config.xml

label="Hello Dashlet" description="My Hello Dashlet"

have to be as following:

label-id="Hello Dashlet" description-id="My Hello Dashlet"

beside adding the translation for the two values: label-id and description-id in the translation files:
webclient_en_US.properties (for english)
webclient.properties (as a default value)

Hope this would help also, especially for those who work on the recent versions of Alfresco.

Best regards
Yazid Erman

Anonymous said...

I have a question please,

Regarding the Freemarker template, which you have called : hello.html.ftl
can we make it editable by the User interface? means can i as a developer let the system admin edit it using the Alfresco Explorer User interface?

i have looked for these files through it, but i haven't found them!

Anonymous said...

Thanks Santoso,

Nice blog and its working fine.
Need your quick help, I want to design a dashlet for alfresco explorer not for share using JSON response or using js script which will return me all the tasks for workflow for all the users. It will be for admin user.
Can you please assist me for the same.
It would be helpful if you could mail me on saket.saraf@gmail.com.

Thanks.