Custom Constrains in Alfresco Model

Most of the Alfresco development project, or rather I say CMS implementations, starts with content modeling where based on the requirement of organization Developers needs to create content types and related set of properties in to the CMS which can later be used by end user. This is very crucial part of development as our much future development would be dependent on content models. For more details on the content modeling you can refer my previous posts.

Content model in alfresco supports properties with much different types like integer, text, any, long etc…It also support constrains to be applied on the particular property where we want to restrict users to feed specific type of values in property. For instance emailId we want to validate the email id then we need to add constrain to the property associated with it.

Following are out of box constrains available in alfresco

Constrain Name Description Allowed Parameters
REGEX Property value matches regular expression. Regular Expression
LENGTH Text property value length must reside within minimum and maximum length limits. minLength and maxLength
MINMAX Numeric property value must reside within minimum and maximum range limits. minValue and maxValue
LIST  Property value must be one of those specified in the list of values. allowedValues and caseSensitive

Constrains can be defined in model as follow and can be added to multiple property according to requirement.

<constraint name="custom:constrainlist" type="LIST">

        <parameter name="allowedValues">








<property name="custom:testproperty">





                 <constraint ref="customconstrainlist"/>



Multiple constrains can be added to one property and one constrain can also be applied to multiple properties.

There are situation where we want this predefined set of values to be fetched from existing database or some other place where those values are defined. To meet this requirement we need to create our custom constrain which will be extension of LIST constrain type.

Step 1:

Define custom constrain in model

<constraint name="custom:mycustomlist" type="" ><parameter name="allowedValues">


Step 2:

Create class CustomConstraint which extends org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint


import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint;
import javax.faces.model.SelectItem;

public class CustomConstraint extends ListOfValuesConstraint {

    public void setAllowedValues(List allowedValues) {

    public void setCaseSensitive(boolean caseSensitive) {

   public void initialize() {

    protected void fetchDataFromDb () {
        List<String> allowedValueList = new ArrayList<String>();
        //create db connection and fetch values

      // iterate though list of values and populate above list           


Step 3:

Add custom constrain to property in which you want to use that.


<property name="custom:testproperty">





                 <constraint ref="custom:mycustomlist"/>




All right now you can go and restart the server and check the effect of this from your user interface for adding properties to user interface please refer my previous posts on content modeling.

Looking for quality Alfresco Web Hosting? Look no further than Arvixe Web Hosting!

Tags: , , , , , , , , , | Posted under Alfresco | RSS 2.0

Author Spotlight


I love opensource technologies working with those technologies from the time I have stepped in to the Software Industry. Alfresco CMS is my area of expertise. I have worked on various complex implementations which involved integration of Alfresco with other technologies, extensively worked with JBPM workflows and Webscripts.

2 Comments on Custom Constrains in Alfresco Model

  1. hachem says:

    Hi mitpatoliya,
    The data in the drop down is not getting refreshed when an item is added to the database.
    What I should change to get this working?
    Thank you.

    • mitpatoliya says:

      You probably need to remove that fetchDataFromDb() from init() and shift all logic to overriden setAllowedValues().

Leave a Reply to hachem Cancel reply

Your email address will not be published. Required fields are marked *