Tuesday, February 16, 2010

Creating Edit Forms for Custom Types in Alfresco Share

Most organizations that will use Alfresco will want to create custom types.
Associated with each custom type is a data model or set of metadata that is unique to that type of document.
To be able to edit document type metadata in Alfresco Share, you need to define an edit form.

Here's a brief example for how to set up and define the metadata for a custom document type and then how to define a Share edit form for that custom type.

Some good resources with getting started with Alfresco Share forms include:

Alfresco Wiki Form Developer Guide page.
Alfresco Wiki Form Examples page.  [Good starting place]
Ed Loves Java on creating Alfresco Share 3.2 forms.
Loftux on Alfresco Forms

First we define a minimum custom Alfresco type. There are four files needed to add this new type to the content model.


<?xml version="1.0" encoding="UTF-8"?>
<!-- Definition of new Model -->
<model name="mm:minmodel" xmlns="http://www.alfresco.org/model/dictionary/1.0">

 <!-- Optional meta-data about the model -->
 <description>MinProperty Model</description>

 <!-- Imports are required to allow references to definitions in other models -->
  <!-- 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" />

 <!-- Introduction of new namespaces defined by this model -->
  <namespace uri="http://www.formtek.com/model/content/1.0" prefix="mm" />

  <constraint name="mm:colorList" type="LIST">
            <parameter name="allowedValues">

  <!-- Enterprise-wide generic document type -->
  <type name="mm:doc">
   <title>Minimum Custom Document</title>
    <property name="mm:freeText">
    <association name="mm:relatedDocuments">
     <title>Related Documents</title>

  <aspect name="mm:colorAble">
   <title>Rainbow Color</title>
    <property name="mm:color">
      <constraint ref="mm:colorList" />

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>

    <!-- Registration of new models -->
    <bean id="minModel.dictionaryBootstrap" parent="dictionaryModelBootstrap" depends-on="dictionaryBootstrap">
        <property name="models">
        <property name="labels">



 <!-- show related documents association on doc property sheet -->
 <config evaluator="node-type" condition="mm:doc">
   <show-association name="mm:relatedDocuments"/>
   <show-property name="mm:freeText"/>

 <config evaluator="aspect-name" condition="mm:colorAble">
            <show-property name="mm:color" />

 <config evaluator="string-compare" condition="Content Wizards">
   <type name="mm:doc" />

 <config evaluator="string-compare" condition="Action Wizards">
   <type name="mm:doc" />

  <!-- The list of content and/or folder types shown in the specialise-type action -->
   <type name="mm:doc" />
   <aspect name="mm:colorAble" />
 <config evaluator="string-compare" condition="Advanced Search">
    <type name="mm:doc" />  
    <meta-data aspect="mm:colorAble" property="mm:color"/>

mm_minmodel.description=Alfresco Example Minimum Domain Model

mm_minmodel.type.mm_doc.title=Min Extended Content
mm_minmodel.type.mm_doc.description=Minimum Extended Content Document
mm_minmodel.property.mm_freeText.title=Additional Details
mm_minmodel.property.mm_freeText.description=Place to enter more details about this document
mm_minmodel.aspect.mm_colorAble.title=Rainbow Color
mm_minmodel.aspect.mm_colorAble.description=Color of the rainbow this document belongs to

The example files above define a simple "Minimum Content Model" for Alfresco. All of these files are kept within the Alfresco repository -- within the alfresco.war file set.

The next file is on the Share side and is used to define a form within Share for editing metadata specific to the custom class just defined.



 <config evaluator="node-type" condition="mm:doc">
             <!-- inherited from cm:content -->
             <show id="cm:name" />
             <show id="cm:title" force="true" />
             <show id="cm:description" force="true" />
             <show id="mimetype" />
             <show id="cm:author" force="true" />
             <show id="size" for-mode="view" />
             <show id="cm:creator" for-mode="view" />
             <show id="cm:created" for-mode="view" />
             <show id="cm:modifier" for-mode="view" />
             <show id="cm:modified" for-mode="view" />
             <!--  specific for mm:doc -->
             <show id="mm:relatedDocuments" />
             <show id="mm:freeText" />

             <!--  aspect mm:colorAble -->             
             <show id="mm:color" />
             <field id="mm:relatedDocuments" label="Related Docs"/>
             <field id="mm:freeText" label="More Information"/>
             <field id="mm:color" label="Color">
                <control template="controls/selectone.ftl">
                   <control-param name="options">Red,Orange,Yellow,Green,Blue,Indigo,Violet</control-param>

With those files in place, you can checkin a document of type mm:doc from the Alfresco Explorer client and then make it available from Alfresco Share. Edit the metadata for the document, and select "Full Metadata Edit Page...".

You should see something like this:

The three new custom fields are now exposed on the Share edit form:  Related Docs, More Information, and Color.


  1. I am able to configure my custom types and they appear in the drop down list, but I do see one minor problem. Once the document type is changed using Change Type, it cannot be changed again. Subsequent selection of Change Type does not list the custom types, the drop down list is empty. Is this how it is supposed to work?

  2. AFAIK That is just because you can only specialise to subtypes of your type, so once you specialise from cm:content to mm:doc you can't specialise anymore, unless you define subtypes for mm:doc