Monday, November 24, 2008

Alfresco workflow package actions

I'm writing this post to serve as a reminder for later need because it's a bit difficult to look for it in Alfresco documentation "jungle" :) (no offense, I'm still grateful that I could access Alfresco's documentation).

Each workflow instance in Alfresco works against a document, the start task "submit" the document, the other tasks in the workflow might add another document, edit attached document, remove attached document and only allowed to read the attached document. This behaviour is set in the workflow model by overriding bpm:packageActionGroup and bpm:packageActionItemGroup.

List of action groups available by default :
  • read_package_item_actions
    allow viewing of package items
  • edit_package_item_actions
    above + allow modification (edit, checkout, ...) of package items
  • edit_and_remove_package_item_actions
    above + allow removal of package items
  • remove_package_item_actions
    allow removal (but not modification) of package items
  • add_package_item_actions
    allow addition of new package items
Custom action also supported but up to now I still have to find out how.

Sample model definition which overrides the default action.
<type name="mynamespace:taskname">
<property name="bpm:packageActionGroup">
<property name="bpm:packageItemActionGroup">

I guess this is enough for now.

Passing values to your freemarker template in alfresco

This story started when my teammate needed the value of JSESSIONID from alfresco and bla bla bla... So, in short, this is how I managed to pass the session id.

  1. Create a simple model (javabean class) to pass the value to the template, in the class create a method to return a Map containing the values needed, the keys used to store the values are the keys that will be accessed in the template.

  2. public Map getTemplateModel() {
    Map result = new HashMap();

    result.put("sessionId", getSessionId());

    return result;

  3. Register the class as a managed bean in WEB-INF/faces-config-custom.xml (pasting the content here is a bit difficult, until I know how to easily paste an xml content to the post I might not post it). Actually it's not that difficult to register a managed bean, just look at the sample in faces-config-beans.xml.
  4. <managed-bean>
    Helper bean providing access to http servlet request's related properties
    and many other things.
  5. Use the bean name as the model passed to the template.
  6. <r:template template="/alfresco/templates/elnusa/elnusa.html.ftl" model="#{Elnusa.templateModel}"/>
  7. Access the value in the template, just like the way default values provided by alfresco are accessed.

That's all, I guess I have to sleep now, already late...

Reference :
  1. Template Guide

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 Sample content :
  2. <#assign name =>
    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">

  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"
  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 :)