cancel
Showing results for 
Search instead for 
Did you mean: 

context in javascript action

ronald
Champ in-the-making
Champ in-the-making
Hello,

http://forums.alfresco.com/viewtopic.php?t=3161&highlight=javascript
http://forums.alfresco.com/viewtopic.php?t=3775&highlight=javascript

I read the above posts and tried a lot but still cannot get parameters into my javascript and i don't know either how to return to my original page from my script.

in my web-client-config-custum.xml i have:

   <config>
      <actions>
         <!– Launch Test Javascript Dialog –>
         <action id="test_js">
            <label>Test Javascript</label>
            <image>/images/icons/add.gif</image>
            <!– action>dialog:testJS</action –>
            <!– action-listener>#{BrowseBean.setupContentAction}</action-listener –>             
            <script>/Company Home/Data Dictionary/Scripts/append testmessage.js%26dummy=dummy1</script>
            <params>
               <param name="id">#{actionContext.id}</param>
            </params>
         </action>
                  
         <!– Add action to more actions menu for each space –>
         <action-group id="document_browse_menu">
            <action idref="test_js" />
         </action-group>
      </actions>
   </config>

I know that to get the context (eg. document and space) in a java action
you can reference your BrowseBean. when you have an action-handler with BrowseBean.setupContentAction.
But how can i use (reference) document and space in my javascript action?

How can i return to for example "/alfresco/faces/jsp/browse/browse.jsp" from my javascript action?

A third question i have is:

Where do the methods exist that are referenced in <config><action><onclick>?

Thank in advance for answering these question!

Kind regards,

Ronald Vermeire
16 REPLIES 16

ronald
Champ in-the-making
Champ in-the-making
Hello,

Anyone knows if this is documented in one of the wikis?

Kind regards,

Ronald Vermeire

ronald
Champ in-the-making
Champ in-the-making
Hello,

Just to stay on top a little.  :mrgreen:
Anyone, or is the question not very clear or ……… ?

Kind regards,

Ronald Vermeire
Software Engineer

kevinr
Star Contributor
Star Contributor
Yes there are wiki docs here:
http://wiki.alfresco.com/wiki/Externalised_Client_Actions

Parameters for javascript actions and standard method based actions are this config block:

<params>
<param name="id">#{actionContext.id}</param>
<param name="dummy">dummy1</param>
</params>
So in this example the "id" arg will be set to the ID of the node the action is running on, and the "dummy" arg will be set to the value of "dummy1".

Note that the args are made available in the 'args' object as name/value pairs as mentioned in the wiki docs.

Cheers,

Kevin

ronald
Champ in-the-making
Champ in-the-making
Hello Kevin,

First of all thanks for the pointer to the Wiki. But i am still not there, still no
parameters in my script. I have done the following. I started of by adding a custom menu item and then i gave the menu something to call namely the script: myparams.js

I configured the following in web-client-config-custom.xml:

    <config>
       <actions>
       <!– Launch js_test Dialog –>
            <action id="js_test">
                <label>Test javascript</label>
                <image>/images/icons/add.gif</image>
                <script>/Company Home/Data Dictionary/Scripts/myparams.js</script>
                <params>
                   <param name="dummy">dummy1</param>
                  <param name="id">#{actionContext.id}</param>                   
               </params>               
            </action>
               
            <!– Add action to more actions menu for each document–>
            <action-group id="document_browse_menu">
                <action idref="js_test" />
            </action-group>
       </actions>
    </config>


The myparams.js script looks like this:

logger.log("–>");

logger.log ("companyhome: " + companyhome)

var mydummy = args["dummy"];
var myid = args["id"];
logger.log("args[0] " + args[0] + " mydummy: " + mydummy + "  myid : "+ myid);

logger.log("<–");


And the logger writes the following output:


16:28:39,781 DEBUG [repo.jscript.RhinoScriptService] Executing script: workspace
://SpacesStore/7cb09a38-6cc4-11db-93a1-a3f83372d0ec
16:28:39,796 DEBUG [repo.jscript.ScriptLogger] –>
16:28:39,796 DEBUG [repo.jscript.ScriptLogger] companyhome: Node Type: {http://w
ww.alfresco.org/model/content/1.0}folder
Node Properties: 12
Node Aspects: [{http://www.alfresco.org/model/content/1.0}auditable, {http://www
.alfresco.org/model/application/1.0}uifacets, {http://www.alfresco.org/model/sys
tem/1.0}referenceable]
16:28:39,796 DEBUG [repo.jscript.ScriptLogger] args[0] /Company Home/Data Dictio
nary/Scripts/myparams.js mydummy: null  myid : null
16:28:39,796 DEBUG [repo.jscript.ScriptLogger] <–
16:28:39,796 DEBUG [repo.jscript.RhinoScriptService] Time to execute script: 15ms


As you can see both dummy and id are null.

This is really all the configuration and code i customized in Alfresco.
What am i missing or doing wrong here?

Thanks in advance!

Kind regards,

Ronald Vermeire

kevinr
Star Contributor
Star Contributor
Can I ask which version of Alfresco you are using, as I'm wondering if you have an earlier version which does not have parameter passing enabled (this is a guess…)

Thanks,

Kevin

ronald
Champ in-the-making
Champ in-the-making
I am using alfresco 1.4. Today i saw a very simular question on this forum.

http://forums.alfresco.com/viewtopic.php?t=3952

But no answers till now, so i am getting curious if this feature is really
available in the current release.

Kind regards,

Ronald Vermeire

kevinr
Star Contributor
Star Contributor
If you read that post you'll see that the "id" parameter is working fine for him, but the others he is trying won't work as they are not primative types - i will reply to it shortly.

I'll take a look at this today, but i'm 99% sure it is working with basic types passed as parameters.

Thanks,

Kevin

ronald
Champ in-the-making
Champ in-the-making
Hello,

I read the other post again and now it worked for him. When i saw your answer i tried some things and i now know what the problem is!

                   <action-group id="document_browse_menu">
            <action idref="test_js" />
         </action-group>


This one does not work

         <action-group id="doc_details_actions">
            <action idref="test_js" />
         </action-group>


This one does not work

         <action-group id="document_browse">
            <action idref="test_js" />
         </action-group>


This one does work


Is this all how it should work, or should i be able to get actionContext.id from document_browse_menu and doc_details_actions?

Kind regards,

Ronald Vermeire

kevinr
Star Contributor
Star Contributor
Glad to hear it. That's rather odd - all those menus have a Node context passed in, so #{actionContext.id} should always be available.

I'm not sure why it's not working for the script execution as other actions within the same actiongroups all access #{actionContext.id} with no problem - otherwise nothing in the app would be working! Smiley Happy If i get time today i'll try your exact use-case in those actiongroups.

Thanks,

Kevin