cancel
Showing results for 
Search instead for 
Did you mean: 

How to render a decorated custom property

douglascrp
World-Class Innovator
World-Class Innovator
Hi.

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.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import org.alfresco.repo.jscript.app.BasePropertyDecorator;
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 {

   @SuppressWarnings("unchecked")
   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;
   }

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

   @Override
   public void setPropertyName(String propertyName) {
      propertyNames = new HashSet<QName>(1);
      propertyNames.add(QName.createQName(propertyName));
   }

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



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

<beans>
   <bean id="customDatePropertiesDecorator" parent="baseDecorator"
      class="com.custom.decorators.CustomDateAttributesDecorator">
      <property name="propertyNames">
         <set>
            <value>{http://www.custom.com/model/content/1.0}dateField1</value>
            <value>{http://www.custom.com/model/content/1.0}dateField2</value>
            <value>{http://www.custom.com/model/content/1.0}dateField3</value>
         </set>
      </property>
   </bean>
</beans>



In the share side, I have this:


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


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.
2 REPLIES 2

afaust
Legendary Innovator
Legendary Innovator
Hello,

for this you would also need to implement a custom renderer on Share side to evaluate the map you put in the JSON through your decorator. AFAIK there is no way for you to access this inner property through configuration alone.

Regards
Axel

douglascrp
World-Class Innovator
World-Class Innovator
Got the idea…
I'll try to implement that now.

Thank you.