title: Dynamic list constraint on Alfresco
body: <p>I'm trying to follow the examples provided in <a href="http://blogs.alfresco.com/wp/jbarmash/2008/08/08/dynamic-data-driven-drop-downs-for-list-properties/" rel="nofollow noreferrer">this post</a>, to create a dynamic list constraint in Alfresco 3.3.</p>
  
  <p>So, I've created my own class extending <code>ListOfValuesConstraint</code>:</p>
  
  <pre><code>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) {
      }
  
      protected void loadData() {
          List&lt;String&gt; values = new LinkedList&lt;String&gt;();
          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);
      }
  }
  </code></pre>
  
  <p><code>ServiceRegistry</code> reference is injected by Spring, and it's working fine. If I only call <code>loadData()</code> from <code>initialize()</code>, it 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.</p>
  
  <p><code>getAllowedValues()</code> is called each time the UI has to display a property having this constraint. The idea on the referred post is to call <code>loadData()</code> from <code>getAllowedValues()</code> 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, so my dropdown only displays <code>-</code>.</p>
  
  <p>BTW, the query I'm doing is: <code>+TYPE:"cm:category" +@cm\:description:"something here"</code>, and it's the same on each case. It works from initialize, but doesn't from getAllowedValues.</p>
  
  <p>Any ideas on why is this happening, or how can I solve it?</p>
  
  <p>Thanks</p>
  
  <p><strong>Edit:</strong> we upgraded to Alfresco 3.3.0g Community yesterday, but we're still having the same issues.</p>