cancel
Showing results for 
Search instead for 
Did you mean: 

execute javascript directly on JSP

ze
Champ in-the-making
Champ in-the-making
Hi,

I try this, to get the person first name, in javascript …

       var name = person.properties.FirstName;
       document.write(name);

but the variavle person is not defined…. Smiley Surprisedops:

can someone give me a litle help here….

thanks very much!
4 REPLIES 4

kevinr
Star Contributor
Star Contributor
There are two things wrong with your script, firstly JavaScript and the Alfresco JavaScript API are case sensitive - so the property name is wrong, you need:

var name = person.properties.firstName;

also the document.write(…) will not work - the document.write() function is part of the web browser JavaScript extensions - the Alfresco javascript engine is pure JavaScript 1.6 with our Alfresco extensions.

Hope this helps,

Kevin

kevinr
Star Contributor
Star Contributor
…I've just read the title of your post Smiley Happy You can't execute Alfresco JavaScript within a JSP and expect it to work…! As i said earlier - the browser JavaScript API is very different to ours.

Kevin

ze
Champ in-the-making
Champ in-the-making
Sorry if i ask dumb questions… but can you tell me where i can get more information how to use javascript in alfresco?

i already read the java script api, but i dont andertand very well this question…

i have to execute something before i can execute this? I can´t put this code directly in JSP files?

thanks….

kevinr
Star Contributor
Star Contributor
The Alfresco JavaScript API can executed from various hook points. It can be used in Rules - so a script can be executed say when a document is uploaded or changed or when a new space is created or similar. It is also possible to execute a script directly via URL using the command servlet. Or you can configure a script to be executed when an action icon is clicked in the web-client UI.
http://wiki.alfresco.com/wiki/JavaScript_API
http://wiki.alfresco.com/wiki/URL_Addressability#Script_Command_Processor
http://wiki.alfresco.com/wiki/Externalised_Client_Actions#Action_Definition_Config_Elements

It cannot be used directly on a JSP page as it is executed withi the context of the server. However it can be used as part of the new Webscripts framework to build interactive pages with only some HTML/templating knowledge plus javascript:
http://wiki.alfresco.com/wiki/Web_Scripts

Hope this helps,

Kevin