AnsweredAssumed Answered

How to render a decorated custom property

Question asked by douglascrp Moderator on May 4, 2014
Latest reply on May 5, 2014 by douglascrp

I'm trying to implement a custom decorator for some custom date properties in my custom model.

I was able to finish the repository side code:

package com.custom.decorators;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
import org.json.simple.JSONAware;
import org.json.simple.JSONObject;

public class CustomDateAttributesDecorator extends BasePropertyDecorator {

   public JSONAware decorate(QName propertyName, NodeRef nodeRef,
         Serializable value) {

      JSONObject map = new JSONObject();

      if (value instanceof Date) {
         SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");

         String date = sdf.format((Date) value);

         map.put("formattedDate", date);

      return map;

   public Set<QName> getPropertyNames() {
      return propertyNames;

   public void setPropertyName(String propertyName) {
      propertyNames = new HashSet<QName>(1);

   public void setPropertyNames(Set<String> propertyNames) {
      this.propertyNames = new HashSet<QName>(propertyNames.size());
      for (String propertyName : propertyNames) {

<?xml version='1.0' encoding='UTF-8'?>

   <bean id="customDatePropertiesDecorator" parent="baseDecorator"
      <property name="propertyNames">

In the share side, I have this:

<template id="isPpra">
   <line index="110" id="date">{custom:dateField1 prop.custom_dateField1}</line>
   <line index="170" id="created">{date}{size}</line>

Using the code above, I see only the property's label, but not the decorated value.

Looking at the network traffic using the Developer Tools on Firefox or Chrome, I see the json object has my property decorated, but it's like

        "properties": {
          "cm:author": "user1",
          "custom:dateField1": {
            "formattedDate": "16/10/2013"
          "cm:modified": {
            "value": "Thu Apr 11 16:22:09 GMT-03:00 2013",
            "iso8601": "2013-04-11T19:22:09.131Z"

How can I get that value and use it to display the decorated property on share?

Thank you in advance.