cancel
Showing results for 
Search instead for 
Did you mean: 

custom java action

showbiz
Champ on-the-rise
Champ on-the-rise
Hi,

I'm new in Alfresco and i want to create an action (with Java Code) applicable to a document.

I have added the followings tags in web-client-config custom


   <config>
      <actions>      
         <action id="myAction">
            <label>MyAction</label>
            <image>/images/icons/add.gif</image>                       
         </action>           
         <!– Add action to more actions menu for each document–>
         <action-group id="document_browse_menu">
            <action idref="myAction" />
         </action-group>        
      </actions>
   </config>

My questions is how i could connect this declaration with Java Code, i have proved to defining the tag 'action' and 'actionListener' but it don't work.

   <config>
      <actions>      
         <action id="myAction">
            <label>MyAction</label>
            <image>/images/icons/add.gif</image>                   
                 <action>es.alfresco.myAction</action>
         </action>           
         <!– Add action to more actions menu for each document–>
         <action-group id="document_browse_menu">
            <action idref="myAction" />
         </action-group>        
      </actions>
   </config>

Thanks in advance
7 REPLIES 7

jarrett
Champ in-the-making
Champ in-the-making
Have you registered your action/ bean in your context.xml file in the extension directory? You'll probably need to add something to the context file located at <tomcat>/shared/classes/alfresco/extension/<your_company->-action-context.xml.

What you'll want to add will look similar to this:

<!– Your Action Bean –>
<bean id="your-action" class="com.your.comapny.action.name" parent="action-executer">
   <property name="nodeService">
      <ref bean="NodeService" />
   </property>
</bean>

showbiz
Champ on-the-rise
Champ on-the-rise
Hi Jarret, thank you for your response.

Yes, i have created the file 'my-action-context.xml' in path ''tomcat>/shared/classes/alfresco/extension/":

<beans>
   <bean id="myAction"
         class="es.sia.alfresco.action.executer.MyActionExecuter"
         parent="actionexecuter">
      <property name="nodeService">
         <ref bean="NodeService" />
      </property>
   </bean>
   <bean id="extension.actionResourceBundles" parent="actionResourceBundles">
      <property name="resourceBundles">
         <list>
            <value>alfresco.extension.custodiaactionmessages</value>
         </list>
      </property>
   </bean>
</beans>

But, ¿how is the calling in the <action-listener> tag, I have proved with:


<action-listener>#{myAction.executeImpl}</action-listener>

But i get this error


javax.faces.el.EvaluationException: Exception while invoking expression #{myAction.executeImpl}
caused by:
javax.faces.el.PropertyNotFoundException: Base is null: myAction

Thank you very  much for your help.

showbiz
Champ on-the-rise
Champ on-the-rise
I have solved a sintaxys error in the declaration of the bean, now a i get this error:

javax.faces.el.EvaluationException: Exception while invoking expression #{myAction.executeImpl}
caused by:
java.lang.NoSuchMethodException: es.sia.alfresco.action.executer.MyActionExecuter.executeImpl(javax.faces.event.ActionEvent)

Why is necesary my method have a ActionEvent parameter?

cheffilet
Champ in-the-making
Champ in-the-making
Because of the scenario if you wishes to retrieve more informations about the current environment being there when an action will be clicked. Therfore the action-listener tag informs alfresco to etablish a faces-binding to a commandlink/commandbutton: There will be something like this generated:

<h:commandLink … actionLister="#{myAction.executeImpl}" value="…" action="…"/>

This method most provide one argument with type of an ActionEvent.

Following example should work:


package es.sia.alfresco.action.executer;
class MyActionExecuter extends … {
  
  public void executeImpl(ActionEvent ae) {
   Object val = ae.getSource();
   //do something with the "clicked source"
  }

}

jayjayecl
Confirmed Champ
Confirmed Champ
Hi Jarret, thank you for your response.

Yes, i have created the file 'my-action-context.xml' in path ''tomcat>/shared/classes/alfresco/extension/":

<beans>
   <bean id="myAction"
         class="es.sia.alfresco.action.executer.MyActionExecuter"
         parent="actionexecuter">
      <property name="nodeService">
         <ref bean="NodeService" />
      </property>
   </bean>
   <bean id="extension.actionResourceBundles" parent="actionResourceBundles">
      <property name="resourceBundles">
         <list>
            <value>alfresco.extension.custodiaactionmessages</value>
         </list>
      </property>
   </bean>
</beans>

But, ¿how is the calling in the <action-listener> tag, I have proved with:


<action-listener>#{myAction.executeImpl}</action-listener>

But i get this error


javax.faces.el.EvaluationException: Exception while invoking expression #{myAction.executeImpl}
caused by:
javax.faces.el.PropertyNotFoundException: Base is null: myAction

Thank you very  much for your help.


You made a mistake in your bean declaration :

<bean id="myAction"
         class="es.sia.alfresco.action.executer.MyActionExecuter"
         parent="action-executer">

If this is still not working, one thing to check is whethet this file is read by Alfresco.
In order to check this, make an XML mistake in this very file, and see if when starting Alfresco, an exception is raised.

joaotpd
Champ on-the-rise
Champ on-the-rise
Hi! …
I'm trying to do the same thing… but i can't get it…
I have the the Tag example (SDK TaggingSample) working with this structure:

alfresco.extension
   
    tagging-context.xml
         tagsModel.xml
         web-client-config-custom.xml
         webclient.properties
org.alfresco.sample
    
    TagActionExecuter.java
         TagActionHandler.java
         tag-action-messages.properties
web.jsp.extension
    
    tag.jsp
but, to run the action I have to go: Run Action… then chose the action… then…
I want to run the action from the document_browse_menu
I've already tried with this in:
web-client-config-custom.xml

<alfresco-config>

   <config evaluator="aspect-name" condition="tag:taggable">
      <property-sheet>
         <show-property name="tag:tags" />
      </property-sheet>
   </config>
  
   <config evaluator="string-compare" condition="Action Wizards">
      <action-handlers>
         <handler name="tag" class="org.alfresco.sample.TagActionHandler" />
      </action-handlers>
   </config>

   <config>
      <actions>
        <action id="tag">
           <label>Tag Document</label>
           <image>/images/icons/tagDoc.gif</image>
           <action-listener>#{tag.executeImpl}</action-listener>
        </action>
         
        <!– Add action to more actions menu for each document –>
        <action-group id="document_browse_menu">
           <action idref="tag" />
        </action-group>
         
      </actions>
   </config>

</alfresco-config>
… but I'm getting this error:

javax.faces.el.EvaluationException: Exception while invoking expression #{tag.executeImpl}
caused by:
java.lang.NoSuchMethodException: org.alfresco.sample.TagActionExecuter.executeImpl(javax.faces.event.ActionEvent)
Can anyone please help??…
Thanks in advance!!

João Duarte

jeyaa
Champ in-the-making
Champ in-the-making
Hi did you found the solution? If so please post it.

Thanks