AnsweredAssumed Answered

Custom action form with custom-selectone.ftl

Question asked by dave84 on Nov 14, 2013
Hi all,
I created a custom doclib action whith custom form dialog to pass parameter to the java action, as described in this link

<a href="http://ecmstuff.blogspot.com.br/2012/04/adding-document-library-actions-in.html">http://ecmstuff.blogspot.com.br/2012/04/adding-document-library-actions-in.html</a>

In my custom form I have to display a custom selectone with static option values, so i created a custom_selectone.ftl
Form is shown correctly when click the action from Share, but the failure message is shown without call my java action and without any error in log file. If I change the property of custom form for example to mimetype property (with mimetype.ftl control) the action is correctly called and no failure message display.

Alfresco version is 4.2.c and these are my configurations:

share-config-custom.xml

<config evaluator="string-compare" condition="invia-ad-ente-action">

         <forms>

              <form>

                 <field-visibility>          
         <show id="enteProperty"/>
                 </field-visibility>

                 <appearance>

                <field id="enteProperty" label="Selezionare l'ente">
                 <control template="/org/alfresco/components/form/controls/custom_selectone.ftl" />
               </field>
            
                 </appearance>

            </form>

        </forms>

    </config>
   
   <!– Document Library Actions config section –>
   <config evaluator="string-compare" condition="DocLibActions">

      <actions>
      
       <action id="invia-ad-ente" type="javascript" label="Invia ad Ente esterno" icon="document-view-in-source-repository">
            <!– Additional parameters for onFormDialog function  –>
         <param name="function">onActionFormDialog</param>
         <param name="itemKind">action</param>
         <param name="itemId">invia-ad-ente-action</param>
         <param name="mode">create</param>
         <param name="destination">{node.nodeRef}</param>
         <param name="successMessage">Success</param>
         <param name="failureMessage">Error</param>
         </action>
      
     </actions>
    
   </config>


custom_selectone.ftl

<#assign controlId = fieldHtmlId + "-cntrl">
<script type="text/javascript">//<![CDATA[
// Here you could call your webscript and load your list
</script>

<div id="${controlId}" class="form-field">
<label for="${fieldHtmlId}">${msg("form.control.my-options.label")}:<#if field.mandatory><span class="mandatory-indicator">${msg("form.required.fields.marker")}</span></#if></label>
<select id="${fieldHtmlId}" name="prop_${field.name}" tabindex="0"
       <#if field.description??>title="${field.description}"</#if>
       <#if field.control.params.size??>size="${field.control.params.size}"</#if>
       <#if field.control.params.styleClass??>class="${field.control.params.styleClass}"</#if>
       <#if field.control.params.style??>style="${field.control.params.style}"</#if>>
      <option value="Ente1">Ente1</option>
      <option value="Ente2">Ente2</option>
      <option value="Ente3">Ente3</option>
</select>
<@formLib.renderFieldHelp field=field />
</div>


action-services-context.xml

<bean id="invia-ad-ente-action" class="custom.action.AlfrescoCustomActionInviaAdEnte" parent="action-executer">
      <property name="nodeService">
         <ref bean="nodeService" />
      </property>
      <property name="contentService">
        <ref bean="ContentService" />
     </property>
     <property name="dictionaryService">
        <ref bean="DictionaryService" />
     </property>
     <property name="copyService">
        <ref bean="CopyService" />
     </property>
     <property name="mimetypeService">
        <ref bean="MimetypeService" />
     </property>

   </bean>


CustomAction.java

package custom.action;


import java.util.List;

import org.alfresco.repo.action.ParameterDefinitionImpl;
import org.alfresco.repo.action.executer.ActionExecuterAbstractBase;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.CopyService;
import org.alfresco.service.cmr.repository.MimetypeService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.search.SearchService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class AlfrescoCustomActionInviaAdEnte extends ActionExecuterAbstractBase {
   
   public static final String VAR_SOURCE = "source";
    public static final String VAR_TARGET = "target";

   private static Log logger = LogFactory.getLog("custom.action");
   
   /**
     * Action constants
     */


   private DictionaryService dictionaryService;
    private NodeService nodeService;
    private SearchService searchService;
   private ContentService contentService;
    private CopyService copyService;
    private MimetypeService mimetypeService;
   
    public static final String PARAM_ENTE = "enteProperty";
   

   /**
    * Set the node service
    *
    * @param nodeService
    *            the node service
    */

    public SearchService getSearchService() {
      return searchService;
   }

   public void setSearchService(SearchService serchService) {
      this.searchService = serchService;
   }
   
   public void setNodeService(NodeService nodeService) {
      this.nodeService = nodeService;
   }

   /**
    * Sets the content service
    *
    * @param contentService
    *            the content service
    */
   public void setContentService(ContentService contentService) {
      this.contentService = contentService;
   }

   public void setDictionaryService(DictionaryService dictionaryService) {
      this.dictionaryService = dictionaryService;
   }

   public void setCopyService(CopyService copyService) {
      this.copyService = copyService;
   }

   public void setMimetypeService(MimetypeService mimetypeService) {
      this.mimetypeService = mimetypeService;
   }
   
   public DictionaryService getDictionaryService() {
      return dictionaryService;
   }

   public NodeService getNodeService() {
      return nodeService;
   }

   public ContentService getContentService() {
      return contentService;
   }

   public CopyService getCopyService() {
      return copyService;
   }

   public MimetypeService getMimetypeService() {
      return mimetypeService;
   }

   @Override
   protected void executeImpl(Action action, NodeRef actionedUponNodeRef) {
      
         
         System.err.println("Action Enti");
         logger.error("Action Enti");
         
          String param_test = (String) action.getParameterValue(PARAM_ENTE);
         logger.error("Action Enti Parametro ente: " + param_test);
   
      

   }

      
   @Override
   protected void addParameterDefinitions(List<ParameterDefinition> paramList) {

      paramList.add(new ParameterDefinitionImpl(PARAM_ENTE,
                DataTypeDefinition.TEXT, true,
                getParamDisplayLabel(PARAM_ENTE)));
      
   }

}





What i did wrong?

Thanks!

Outcomes