Search code examples
javasharealfrescoalfresco-sharespring-surf

How setup spring surf form Alfresco share with dinamic variables from a properties file


Hi i have write a spring surf form extensions for the software alfresco, in the specific a dropdown where i want to put the value on a dynamic way reading the value from alfresco or a properties file here the myaction-share-amp-actions-extension-modules:

<extension>
.................................................................
<config evaluator="string-compare" condition="signed">
       <forms>
            <form>
              <field-visibility>
                        ............................................
                        <show id="my_form_sign_firma.tipo"/>
                        ...................................     
              </field-visibility>
              <appearance>
.....................



<field id="my_form_sign_firma.tipo" label-id="property.form.sign.my_form_sign_firma.tipo">  
 <control template="/org/alfresco/components/form/controls/selectone.ftl">  
<control-param name="options">${value1},${value2},${value3}</control-param>
 </control>
</field>     
....................

or in alternative

....................

<field id="my_form_sign_firma.tipo" label-id="property.form.sign.my_form_sign_firma.tipo"> 
<control-param name="options">${valueX}</control-param>
 <!-- where valueX= "value1,value2,value3" -->
 </control>
</field>
....................  
                        </appearance>
                    </form>
                </forms>
            </config> 

...........................................

</extension>

And the bean for load the properties is set on the share-config.xml file:

<bean id="configurazioniBeanCompletoLocale" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath*:it/test/properties/myalfresco.properties</value>
</list>
</property>
<property name="ignoreResourceNotFound" value="true" />
<property name="ignoreUnresolvablePlaceholders" value="true" />
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
<property name="propertiesPersister">
 <bean class="org.alfresco.config.AlfrescoPropertiesPersister" />
</property>
</bean>

And the properties file is set on the share-config.xml file:

classpath*:it/test/properties/myalfresco.properties

And the file myalfresco.properties contains:

value1=hello
value2=hi
value3=goodbye
valueX=hello,hi,goodbye

in alternative i can accept to use property of a specific file on alfresco if anyone know how to do for example :

Repository/Data Dictionary/configuration.txt with properties of a aspect "Configurator" with properties:

value1=hello
value2=hi
value3=goodbye
valueX=hello,hi,goodbye

There is a way to do one of these ?

UPDATE:

I will now try to write on paper a full solution on this link : https://community.alfresco.com/thread/233246-how-setup-spring-surf-form-with-dinamic-variables-from-a-properties-file

Here you can find another example similar to this case: https://community.alfresco.com/thread/209460-dynamic-selectone-in-alfresco-share


Solution

  • As said by Vikash, I would suggest you to create your custom form control (put it in the src/main/amp/config/alfresco/web-extension/site-webscripts/org /alfresco /components/form/controls/mycontrol.ftl folder).

    Inside, you will call a custom webscript you created (which will get the values of your file). This is the trivial part, I don't feel the need to show you an example.

    You can look at this (simplified) example for the ftl part :

    ...
    <select id="${fieldHtmlId}" name="${field.name}" tabindex="0"
         <#if field.description??>title="${field.description}"</#if>
    </select>
    ...
    <script type="text/javascript">//<![CDATA[
    YAHOO.util.Event.onContentReady("${fieldHtmlId}", function ()
    {
        Alfresco.util.Ajax.jsonGet({
            url: encodeURI(Alfresco.constants.PROXY_URI + '/myserviceuri'),
            successCallback:
            {
                fn: function loadWebscript_successCallback(response, config)
                {
                    var obj = eval('(' + response.serverResponse.responseText + ')');
                    if (obj)
                    {
                        for (i = 0; i < obj.length; i++) {
                                var newOption = document.createElement('option');
                                newOption.value = obj[i].id;
                                newOption.text = obj[i].name;
                                YAHOO.util.Dom.get("${fieldHtmlId}").options.add(newOption);
                        }
                    }
                }
            }
        });
    
    }, this);
    //]]></script>
    

    You can then use it this way :

    <field id="my_form_sign_firma.tipo" label-id="property.form.sign.my_form_sign_firma.tipo">  
     <control template="/org/alfresco/components/form/controls/mycontrol.ftl">
     </control>
    </field>