title: Custom (separate) metadata form in alfresco share
body: <p><strong>Seemingly simple requirement</strong></p>
  
  <p>I need a form containing 4 fields (textfield, authority, and date x2), that behaves exactly as does the edit metadata form, the fields representing 4 properties on the node.</p>
  
  <p>This form however, should be available as a separate UI from the edit-metadata form, preferably in the way a UI-action is; a button with icon in the DocLibActions, and a popup form when that is clicked.</p>
  
  <p><strong>Encountered problems</strong></p>
  
  <p>My problem with using the UI action mechanism, is that I cannot link the fields to the properties. Therefore, each time the form opens, the current values available on the node are not loaded. Also, appropriate constraints are not automatically enforced. I cannot think of another way to implement this requirement either.</p>
  
  <p><strong>The UI action way</strong></p>
  
  <p>Starting it out as a UI action, I tried accessing the node in a custom field control ftl using the <code>form.destination</code> model variable holding the noderef. However, when I wanted to get the node properties with that, it turned out the <code>companyhome</code> object required for that in ftl is unavailable to a form control.</p>
  
  <p>I then proceeded to write a custom java webscript that returns the 4 properties I need using a given nodeRef, and called it from my custom field control using javascript. This presents the following two issues:</p>
  
  <ul>
  <li>I have to pass the retrieved values to the form fields myself, presenting quite a challenge for the <code>date.ftl</code> controls, but much more even the <code>authority.ftl</code> control.</li>
  <li>Calling a webscript from the client side javascript adds another round-trip.</li>
  </ul>
  
  <p><strong>Current form definition</strong></p>
  
  <pre><code>&lt;config evaluator="string-compare" condition="my-action"&gt;
        &lt;forms&gt;
           &lt;form&gt;
              &lt;field-visibility&gt;
                 &lt;show id="textProperty" /&gt;
                 &lt;show id="authorityProperty" /&gt;
                 &lt;show id="dateProperty1" /&gt;
                 &lt;show id="dateProperty2" /&gt;
              &lt;/field-visibility&gt;
  
              &lt;appearance&gt;
                  &lt;set id="generalSet" appearance="bordered-panel" label="General" /&gt;
                  &lt;field id="textProperty" label="textProp" set="generalSet"&gt;
                      &lt;control template="/org/alfresco/components/form/controls/propertyBasedTextfield.ftl"&gt;
                          &lt;control-param name="propertyProvider"&gt;/alfresco/service/mark/custom/nodeProperties&lt;/control-param&gt;
                      &lt;/control&gt;
                  &lt;/field&gt;
  
                 &lt;field id="authorityProp" label="Authority" set="generalSet" &gt;
                     &lt;control template="/org/alfresco/components/form/controls/authority.ftl" &gt;
                      &lt;control-param name="compactMode"&gt;true&lt;/control-param&gt;
                     &lt;/control&gt;
                  &lt;/field&gt;
                  &lt;field id="dateProperty1" label="Date 1" set="generalSet"&gt;
                      &lt;control template="/org/alfresco/components/form/controls/date.ftl" /&gt;
                  &lt;/field&gt;
                  &lt;field id="dateProperty2" label="Date 2" set="generalSet"&gt;
                      &lt;control template="/org/alfresco/components/form/controls/date.ftl" /&gt;
                  &lt;/field&gt;
              &lt;/appearance&gt;
           &lt;/form&gt;
        &lt;/forms&gt;
     &lt;/config&gt;
  </code></pre>
  
  <p>How can I best go about implementing this requirement? Note that using a UI action is not mandatory; I can realize this any way I want.</p>