Alfresco Custom Data Lists

Summary

The data lists feature allows site members to create and manage lists of data relevant to the site. Users can work with their own lists and can also contribute to lists created by other site members. Out of the box there are many list templates provided such as: Contact list, Event list, Issue list, To-do list, Feedback list, etc.

Since there are a limited number of canned or out of the box data lists, you will likely need to create your own custom datalist.

To do this, you’ll need to create a custom model file that will define the data list essentially. You’ll also need a context file that references the custom model and finally, make modifications to share-config-custom.xml so that your data list will register and display in your Share site. Be aware that I was able to successfully create a custom data-list using these steps on Alfresco versions 3.4.x and 4.x. I did not test in 3.3, 3.2 or before.

Below are the steps to accomplish this.

Custom Model File

I have called this one slModel.xml to be placed in the extensions directory. This is usually in <alfresco_install_dir>/tomcat/shared/classes/alfresco/extension directory:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Definition of new Model -->
<model name="sl:slDatalist" xmlns="http://www.alfresco.org/model/dictionary/1.0">
 <!-- Optional meta-data about the model --> 
 <description>KB datalist</description>
 <author>Harlin Seritt</author>
 <version>1.0</version>
 <!-- Imports are required to allow references to definitions in other models --> 
 <imports>
     <!-- Import Alfresco Dictionary Definitions -->
     <import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d"/>
     <!-- Import Alfresco Content Domain Model Definitions -->
     <import uri="http://www.alfresco.org/model/content/1.0" prefix="cm"/>
     <!-- Import Alfresco Data List Model Definitions -->
     <import uri="http://www.alfresco.org/model/datalist/1.0" prefix="dl"/>
 </imports>

<!-- Introduction of new namespaces defined by this model --> 
 <namespaces>
     <namespace uri="sl.customlists.com" prefix="sl"/>
 </namespaces>
 <types>
 <!-- Data list defintions For this model go here -->
     <type name="sl:slArticle">
         <title>SL Article</title>
         <description>Simple Article</description>
         <parent>dl:dataListItem</parent>

         <properties>
             <property name="sl:slTitle">
                 <title>Title</title>
                 <type>d:text</type>
                 <mandatory>true</mandatory>
             </property>

             <property name="sl:slContent">
                 <title>Content</title>
                 <type>d:text</type>
                 <mandatory>false</mandatory>
             </property>
         </properties> 

         <associations>
             <association name="sl:slAttachments">
                 <title>Attachements</title>
                 <source>
                     <mandatory>false</mandatory>
                     <many>true</many>
                 </source>
                 <target>
                     <class>cm:content</class>
                     <mandatory>false</mandatory>
                     <many>true</many>
                 </target>
             </association>
         </associations>
     </type>
 </types> 
</model>

Next, you’ll need to create a context file. This file (slModel-context.xml) needs to be placed in the extension directory :

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
<beans>
    <!-- Registration of new models --> 
    <bean id="sl.extension.dictionaryBootstrap" parent="dictionaryModelBootstrap" depends-on="dictionaryBootstrap">
    <property name="models">
        <list>
            <value>alfresco/extension/slModel.xml</value>
        </list>
    </property>
 </bean>

<!-- Shows how to add an additional model if needed
<bean id="extension.mtg.dictionaryBootstrap" parent="dictionaryModelBootstrap" depends-on="dictionaryBootstrap">
 <property name="models">
     <list>
         <value>alfresco/extension/myOtherDatalistModel.xml</value>
     </list>
 </property>
</bean>
-->

</beans>

Last, add these configs to the share-config-custom.xml file (to be overwritten in the web-extensions directory usually in tomcat/shared/classes/web-extension):<config evaluator=”model-type” condition=”sl:slArticle”> <forms>

     <!-- Create item form -->
     <form>
         <field-visibility>
             <show id="sl:slTitle" /> 
             <show id="sl:slContent" /> 
             <show id="sl:slAttachments" /> 
         </field-visibility>
         <create-form template="/org/alfresco/components/data-lists/forms/dataitem.ftl" />
         <appearance>
             <field id="sl:slTitle">
                 <control template="/org/alfresco/components/form/controls/textarea.ftl" /> 
             </field>
             <field id="sl:slContent">
                 <control template="/org/alfresco/components/form/controls/textarea.ftl" /> 
             </field> 
             <field id="sl:slAttachments">
                 <control>
                     <control-param name="startLocation">{doclib}</control-param>
                 </control>
             </field>
         </appearance>
     </form>

 <!-- Data Grid view -->
 <form id="datagrid">
      <field-visibility> 
          <show id="sl:slTitle" /> 
          <show id="sl:slContent" /> 
          <show id="sl:slAttachments" /> 
      </field-visibility>
 </form>
</forms>
</config>

 <!-- Edit view -->
 <config evaluator="node-type" condition="sl:slArticle">
 <forms>
     <!-- Edit marketing item form -->
     <form>
          <field-visibility> 
              <show id="sl:slTitle" /> 
              <show id="sl:slContent" /> 
              <show id="sl:slAttachments" /> 
          </field-visibility>
          <create-form template="/org/alfresco/components/data-lists/forms/dataitem.ftl" />
          <appearance>
              <field id="sl:slTitle">
                 <control template="/org/alfresco/components/form/controls/textarea.ftl" /> 
              </field>
              <field id="sl:slContent">
                  <control template="/org/alfresco/components/form/controls/textarea.ftl" /> 
              </field> 
              <field id="sl:slAttachments">
                  <control>
                      <control-param name="startLocation">{doclib}</control-param>
                  </control>
              </field>
          </appearance>
     </form>
 </forms>
</config>

Add these in place and restart Alfresco. You can then go to any Share site and add this datalist:

<screenshot>

Choose the SL Article data list:

<screenshot>

Add data:

<screenshot>

Now, you have a custom data list!

Cheers! -H.S.