How use PageLink to call a Action Backend

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
4535992
Established Member II

How use PageLink to call a Action Backend

I everyone, i just put myself in the world of customize page and template of Alfresco Share, i have succeded to call a backend action with a PageLink extensions but for some reason i can't retrieve a correct form.

In the following case i'm tring to adding a menu item to the "Create..." menu in DocLib  and call a action java backend.

I'm start by consulting this link: https://docs.alfresco.com/5.1/tasks/dev-extensions-share-tutorials-add-menuitem-create-menu.html

The only difference is i don't want to use a model-type but instead call a action when i submit the form.

It's hard to explain with word so i put some code and some screenshoot.

I use Alfresco Community 5.2.f and SDK 3.0.0.

####################

## AMP REPO

####################

----------------------------------------------------------------------------------------------------------------------------------

/src/main/java/it/abd/alfresco/actions/MyCreateContentAction.java

------------------------------------------------------------------------------------------------------------------------------------------------------

public class MyCreateContentAction extends ActionExecuterAbstractBase {

    private static org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(MyCreateContentAction.class);

    private ServiceRegistry serviceRegistry;

    public void setServiceRegistry(ServiceRegistry serviceRegistry)
    {
        this.serviceRegistry = serviceRegistry;
    }

    @SuppressWarnings("unused")
    @Override
    protected void executeImpl(Action action, NodeRef actionedUponNodeRef)  {        
        try{
            logger.debug("Eseguo l'azione :" + MyCreateContentAction.class.getName());
            
            logger.debug(Arrays.toString(action.getParameterValues().entrySet().toArray()));
            
            String name = (String)action.getParameterValue("cm:name");
            String content = (String)action.getParameterValue("cm:content");
            String title = (String)action.getParameterValue("cm:title");
            String description= (String)action.getParameterValue("cm:description");
            String mimetype = (String)action.getParameterValue("mimetype");
        } catch (Throwable e) {
            logger.error(e.getMessage(), e);        
            throw new RuntimeException(e);
        }
    }

    /**
     * Load the parameter definitions common across all signature types
     *
     */
    protected void addParameterDefinitions(List<ParameterDefinition> paramList)
    {
        paramList.add(new ParameterDefinitionImpl("cm:name", DataTypeDefinition.TEXT, false, getParamDisplayLabel("cm:name")));
        paramList.add(new ParameterDefinitionImpl("cm:content", DataTypeDefinition.TEXT, false, getParamDisplayLabel("cm:content")));
        paramList.add(new ParameterDefinitionImpl("cm:title", DataTypeDefinition.TEXT, false, getParamDisplayLabel("cm:title")));
        paramList.add(new ParameterDefinitionImpl("cm:description", DataTypeDefinition.TEXT, false, getParamDisplayLabel("cm:description")));
        paramList.add(new ParameterDefinitionImpl("mimetype", DataTypeDefinition.TEXT, false, getParamDisplayLabel("mimetype")));
    }

}

-------------------------------------------------------------------------------------------------------------------------------

src/main/resources/alfresco/module/repo-amp/context/service-my-create-content-context.xml

----------------------------------------------------------------------------------------------------------------------------------

<?xml version='1.0' encoding='UTF-8'?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
          http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
          
    <bean id="service-my-create-content-action" class="it.abd.alfresco.actions.MyCreateContentAction" parent="action-executer">
        <property name="serviceRegistry">
            <ref bean="ServiceRegistry" />
        </property>
    </bean>
</beans>

----------------------------------------------------------------------------------------------------------------------------------

####################

## AMP SHARE

####################

----------------------------------------------------------------------------------------------------------------------------------

src/main/resources/alfresco/web-extension/site-data/extensions/service-my-create-content-docx-extension.xml

----------------------------------------------------------------------------------------------------------------------------------

<extension>
    <modules>
        <module>
            <id>service-my-create-content-docx-extension</id>
            <version>1.0</version>
            <auto-deploy>true</auto-deploy>
            <configurations>
                <config evaluator="string-compare" condition="DocumentLibrary">
                    <create-content>
                        
                        <content id="my-create-content-docx" label="create.docx.menu.item.label" icon="text" type="pagelink">
                            <param name="page">service-my-create-content-docx?itemKind=action&amp;itemId=service-my-create-content-action&amp;nodeRef={nodeRef}&amp;destination={nodeRef}&amp;itemId=service-my-create-content-action&amp;mimeType=application/vnd.oasis.opendocument.text</param>
                        </content>
                    </create-content>
                </config>
            </configurations>
        </module>
    </modules>
</extension>

----------------------------------------------------------------------------------------------------------------------------------

src/main/resources/alfresco/web-extension/site-data/pages/service-my-create-content-docx.xml

----------------------------------------------------------------------------------------------------------------------------------

<?xml version='1.0' encoding='UTF-8'?>
<page>
   <title>create.docx.page.title</title>
   <title-id>create.docx.page.title-id</title-id>
   <description>create.docx.page.description</description>
   <description-id>create.docx.page.description-id</description-id>
   <template-instance>service-my-create-content/service-my-create-content</template-instance>
   <authentication>user</authentication>
</page>

----------------------------------------------------------------------------------------------------------------------------------

src/main/resources/alfresco/web-extension/site-data/template-instances/service-my-create-content/service-my-create-content.xml

----------------------------------------------------------------------------------------------------------------------------------

<template-instance>
   <template-type>org/alfresco/extension/service-my-create-content/service-my-create-content</template-type>
   <properties>
      <pageFamily>myCreateContent</pageFamily>
      <!--  <container>documentLibrary</container> -->
       <columns>2</columns>
       <rows>3</rows>
   </properties>
   <components>

      <component>
         <region-id>title</region-id>
         <sub-components>
            <sub-component id="default">
               <evaluations>
                  <evaluation id="site">
                     <evaluators>
                        <evaluator type="site.component.evaluator"/>
                     </evaluators>
                     <url>/components/title/collaboration-title</url>
                  </evaluation>
                  <evaluation id="repo">
                     <url>/components/title/simple-title</url>
                     <properties>
                        <title>title.repository</title>
                        <subtitle>title.browser</subtitle>
                     </properties>
                  </evaluation>
               </evaluations>
            </sub-component>
         </sub-components>
      </component>

      <component>
         <region-id>navigation</region-id>
         <sub-components>
            <sub-component id="default">
               <evaluations>
                  <evaluation id="site">
                     <evaluators>
                        <evaluator type="site.component.evaluator"/>
                     </evaluators>
                     <url>/components/navigation/collaboration-navigation</url>
                  </evaluation>
               </evaluations>
            </sub-component>
         </sub-components>
      </component>

      <!-- Create Content Form Manager -->
      
      <component>
         <region-id>service-my-create-content-form-mgr</region-id>
         <url>/components/service-my-create-content/service-my-create-content-form-mgr</url>
      </component>

      <!-- Create Content Form -->
      <component>
         <region-id>service-my-create-content-form</region-id>
             <url>/components/form?itemKind=action&amp;itemId=service-my-create-content-action&amp;nodeRef={nodeRef}&amp;mimeType={mimeType}&amp;destination={destination}</url>
            <properties>
                <itemKind>action</itemKind>
                <itemId>service-my-create-content-action</itemId>
                <!--<itemKind>type</itemKind>-->
                <!-- <itemId>{itemId}</itemId> -->
                <mode>create</mode>
                <submitType>json</submitType>
                <formUI>true</formUI>
                <showCaption>true</showCaption>
                <showResetButton>true</showResetButton>
                <showCancelButton>true</showCancelButton>
                
                <editInline>true</editInline>             
                <destination>{nodeRef}</destination>
                <nodeRef>{nodeRef}</nodeRef>
                <redirect>/share/page/document-details?nodeRef={nodeRef}</redirect>
                
            </properties>
      </component>   
   </components>
</template-instance>

----------------------------------------------------------------------------------------------------------------------------------

/src/main/resources/alfresco/web-extension/templates/org/alfresco/extension/service-my-create-content/service-my-create-content.ftl

----------------------------------------------------------------------------------------------------------------------------------

<#include "/org/alfresco/include/alfresco-template.ftl" />
<@templateHeader />

<@templateBody>
   <@markup id="alf-hd">
   <div id="alf-hd">
      <@region scope="global" id="share-header" chromeless="true"/>
   </div>
   </@>
   <@markup id="bd">
   <div id="bd">
      <div class="share-form">
         <@region id="service-my-create-content-form-mgr" scope="template" />        
         <@region id="service-my-create-content-form" scope="template" />
      </div>
   </div>
   </@>
</@>

<@templateFooter>
   <@markup id="alf-ft">
   <div id="alf-ft">
      <@region id="footer" scope="global" />
   </div>
   </@>
</@>

----------------------------------------------------------------------------------------------------------------------------------

/src/main/resources/alfresco/web-extension/site-webscripts/it/abd/service-my-create-content/org/alfresco/components/form-mgr/service-my-create-content-form-mgr.get.desc.xml

----------------------------------------------------------------------------------------------------------------------------------

<webscript>
  <shortname>my-create-content-mgr</shortname>
  <description>My Create Content Manager Component</description>
  <url>/components/service-my-create-content/service-my-create-content-form-mgr</url>
</webscript>

----------------------------------------------------------------------------------------------------------------------------------

/src/main/resources/alfresco/web-extension/site-webscripts/it/abd/service-my-create-content/org/alfresco/components/form-mgr/service-my-create-content-form-mgr.get.html.ftl

----------------------------------------------------------------------------------------------------------------------------------

<#include "/org/alfresco/include/alfresco-macros.lib.ftl" />
<script type="text/javascript">//<![CDATA[
/**
 * MyCreateContentMgr template.
 *
 * @namespace Alfresco
 * @class Alfresco.MyCreateContentMgr
 */
(function()
{
   /**
    * YUI Library aliases
    */
   var Dom = YAHOO.util.Dom;

   /**
    * Alfresco Slingshot aliases
    */
   var $siteURL = Alfresco.util.siteURL;

   /**
    * MyCreateContentMgr constructor.
    *
    * @param {String} htmlId The HTML id of the parent element
    * @return {Alfresco.MyCreateContentMgr} The new MyCreateContentMgr instance
    * @constructor
    */
   Alfresco.MyCreateContentMgr = function MyCreateContentMgr_constructor(htmlId)
   {
      Alfresco.MyCreateContentMgr.superclass.constructor.call(this, "Alfresco.MyCreateContentMgr", htmlId);
      
      /* Decoupled event listeners */
      YAHOO.Bubbling.on("formContentReady", this.onFormContentReady, this);
      //YAHOO.Bubbling.on("beforeFormRuntimeInit", this.onBeforeFormRuntimeInit, this);
      
      return this;
   };

   YAHOO.extend(Alfresco.MyCreateContentMgr, Alfresco.component.Base,
   {
      /**
       * Object container for initialization options
       *
       * @property options
       * @type object
       */
      options:
      {
         /**
          * Is the created type expected to be a container?
          * The manager needs to know whether the following page is document-details or folder-details.
          *
          * @property isContainer
          * @type boolean
          * @default false
          */
         isContainer: false,
         
         /**
          * Current siteId.
          *
          * @property siteId
          * @type string
          */
         siteId: null
      },

      /**
       * Event handler called when the "formContentReady" event is received
       */
      onFormContentReady: function MyCreateContentMgr_onFormContentReady(layer, args)
      {
         // change the default 'Submit' label to be 'Save'
         var submitButton = args[1].buttons.submit;
         submitButton.set("label", this.msg("my-create-content-mgr-button.create"));
         
         // add a handler to the cancel button
         var cancelButton = args[1].buttons.cancel;
         cancelButton.addListener("click", this.onCancelButtonClick, null, this);
      },
      
      /**
       * Event handler called when the "beforeFormRuntimeInit" event is received
       */
       /*
      onBeforeFormRuntimeInit: function MyCreateContentMgr_onBeforeFormRuntimeInit(layer, args)
      {
         args[1].runtime.setAJAXSubmit(true,
         {
            successCallback:
            {
               fn: this.onCreateContentSuccess,
               scope: this
            },
            failureCallback:
            {
               fn: this.onCreateContentFailure,
               scope: this
            }
         });
      },
      */
      /**
       * Handler called when the metadata was updated successfully
       *
       * @method onCreateContentSuccess
       * @param response The response from the submission
       */
       /*
      onCreateContentSuccess: function MyCreateContentMgr_onCreateContentSuccess(response)
      {
         var nodeRef = null;
         if (response.json && response.json.persistedObject)
         {
            // Grab the new nodeRef and pass it on to _navigateForward() to optionally use
            nodeRef = new Alfresco.util.NodeRef(response.json.persistedObject);
            
            // Activity post - documents only
            if (!this.options.isContainer)
            {
              Alfresco.Share.postActivity(this.options.siteId, "org.alfresco.documentlibrary.file-created", "{cm:name}", "document-details?nodeRef=" + nodeRef.toString(),
              {
                 appTool: "documentlibrary",
                 nodeRef: nodeRef.toString()
              }, this.bind(function() { this._navigateForward(nodeRef); }));
            }
         }
      },
      */
      /**
       * Handler called when the metadata update operation failed
       *
       * @method onCreateContentFailure
       * @param response The response from the submission
       */
      /*
      onCreateContentFailure: function MyCreateContentMgr_onCreateContentFailure(response)
      {
         var errorMsg = this.msg("my-create-content-mgr.create.failed");
         if (response.json && response.json.message)
         {
            errorMsg = errorMsg + ": " + response.json.message;
         }
         
         Alfresco.util.PopupManager.displayPrompt(
         {
            title: this.msg("my-create-content-mgr.message.failure"),
            text: errorMsg
         });
      },
      */
      /**
       * Called when user clicks on the cancel button.
       *
       * @method onCancelButtonClick
       * @param type
       * @param args
       */     
      onCancelButtonClick: function MyCreateContentMgr_onCancel(type, args)
      {
         this._navigateForward();
      },
      
      /**
       * Displays the corresponding details page for the current node
       *
       * @method _navigateForward
       * @private
       * @param nodeRef {Alfresco.util.NodeRef} Optional: NodeRef of just-created content item
       */
      _navigateForward: function MyCreateContentMgr__navigateForward(nodeRef)
      {
         // Have we been given a nodeRef from the Forms Service?
         if (YAHOO.lang.isObject(nodeRef))
         {
            window.location.href = $siteURL((this.options.isContainer ? "folder" : "document") + "-details?nodeRef=" + nodeRef.toString());
         }
         else if (document.referrer)
         {
            // Did we come from the document library? If so, then direct the user back there
            if (document.referrer.match(/documentlibrary([?]|$)/) || document.referrer.match(/repository([?]|$)/))
            {
               // go back to the referrer page
               history.go(-1);
            }
            else
            {
               document.location.href = document.referrer;
            }
         }
         else if (this.options.siteId && this.options.siteId !== "")
         {
            // In a Site, so go back to the document library root
            window.location.href = $siteURL("documentlibrary");
         }
         else
         {
            window.location.href = Alfresco.constants.URL_CONTEXT;
         }
      }
   });
})();

//]]></script>

<@markup id="widgets">
   <@createWidgets />
</@>

<@markup id="html">
   <@uniqueIdDiv>
      <div class="form-manager">
         <h1>Crea Documento</h1>
      </div>
   </@>
</@>

----------------------------------------------------------------------------------------------------------------------------------

/src/main/resources/alfresco/web-extension/site-webscripts/it/abd/service-my-create-content/org/alfresco/components/form-mgr/service-my-create-content-form-mgr.get.js

----------------------------------------------------------------------------------------------------------------------------------

<import resource="classpath:/alfresco/templates/org/alfresco/import/alfresco-util.js">

function main() {
    var siteName = (page.url.templateArgs.site != null) ? page.url.templateArgs.site : "";
    var forwardUrl = (page.url.args.forwardUrl != null) ? page.url.args.forwardUrl : "";
   // Need to know what type of node this is - document or folder
   // AlfrescoUtil.param("nodeRef");    
   // Widget instantiation metadata...
   var widget = {
      id : "MyCreateContentMgr",
      name : "Alfresco.MyCreateContentMgr",

      options : {
         //siteId : model.siteName,
         siteId : (page.url.templateArgs.site != null) ? page.url.templateArgs.site : "",
         forwardUrl : forwardUrl,     
         isContainer: "true" == ((page.url.args.isContainer != null) ? page.url.args.isContainer : "false")
         //orangeDsCertificateChoiceMessage : msg.get("certificateChoice.label.needChoice")
      }
   };
   model.widgets = [widget];
}
main();

----------------------------------------------------------------------------------------------------------------------------------

/src/main/resources/alfresco/web-extension/site-webscripts/it/abd/service-my-create-content/org/alfresco/components/form-mgr/service-my-create-content-form-mgr.get.properties

----------------------------------------------------------------------------------------------------------------------------------

my-create-content-mgr.heading=Crea Contenuto
my-create-content-mgr.create.failed=Fallito il creamento del contenuto
my-create-content-mgr.message.failure=Fallito il creamento del contenuto
my-create-content-mgr-button.create=Crea

----------------------------------------------------------------------------------------------------------------------------------

The code is done here the screenshot of what i have done on share:

How you can see whe i click on "Create" of share (cirlce red), i have a new option "Create an DOCX text Document"(circle  blue).

After i click on that new voice i'm corrected reditrect to the form:

but the form is wrong (how you can see on the screenshot), i cannot set the labels for the inputs, and i don't find any way to manage that with the "/components/form/" webscript.

If i click on the Submit button i'm reach the java action backend like i want, it's jus the form i can't customize or repair in any way.

I'm desperate for find a solution to this.

Ty in advance for any help.

2 Replies
ashitasaxena
Active Member

Re: How use PageLink to call a Action Backend

Hi 

As per my understanding,according to your requirement calling java backend action is a second step.The very first thing we want here is to redirect to a " create-content " page(in your case it is service-my-create-content-docx page ) of custom type mycc:document. 

As you mentioned in your code,in extension module under create-content section, item-id parameter is mycc:document that is a custom type that will be set on your content . Thus you have to configure this form of custom type mycc:document in the same file extension-modules.xml you have configured the pagelink ,inorder to appear in share .And I am unable to see your custom type mycc:document in your code .Have you created this custom type in your content model.These are the possible reasons you are unable to retrieve correct form in share .

4535992
Established Member II

Re: How use PageLink to call a Action Backend

I'm very sorry, you are right it was a mistake on my copy and paste of code, iìm actually use the action id like value for the "itemId" parameter because i'm trying to use the "action" for the "itemKind" parameter on the template.

ty for the clarification.