AnsweredAssumed Answered

Dynamic list constraint

Question asked by ajperez on Jul 6, 2010
Latest reply on Jun 6, 2012 by glaenen
Hi,

I'm trying to follow the examples provided in this post, to create a dynamic list constraint in Alfresco 3.3.

So, I've created my own class extending ListOfValuesConstraint:


public class MyConstraint extends ListOfValuesConstraint {

   private static ServiceRegistry registry;

   @Override
   public void initialize() {
      loadData();
   }

   @Override
   public List getAllowedValues() {
      loadData();
      return super.getAllowedValues();
   }

   @Override
   public void setAllowedValues(List allowedValues) {
   }

   // Getters and setters for service registry and other things

   protected void loadData() {
      List<String> values = new LinkedList<String>();
      String query = "+TYPE:\"cm:category\" +@cm\\:description:\"" + tipo + "\"";
      StoreRef storeRef = new StoreRef("workspace://SpacesStore");
      ResultSet resultSet = registry.getSearchService().query(storeRef, SearchService.LANGUAGE_LUCENE, query);
      // … values.add(data obtained using searchService and nodeService) …

      if (values.isEmpty()) {
         values.add("-");
      }
      super.setAllowedValues(values);
   }
}
If I only call "loadData()" from initialize(), it works fine: executes the Lucene query, gets the data, and the dropdown displays it correctly. Only that it's not dynamic: data doesn't get refreshed unless I restart the Alfresco server.

"getAllowedValues()" is called each time the UI has to display a property having this constraint. The idea on the referred post is to call "loadData()" from "getAllowedValues()" too, so the values will be actually dynamic. But when I do this, I don't get any data. The Lucene query is the same, but returns 0 results :-?

(BTW, the query I'm doing is: +TYPE:"cm:category" +@cm\:description:"something here")

Any ideas on why is this happening, or how can I solve it?

Thanks

Outcomes