Executing Web Scripts at Render time

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2010 10:46 PM
Hey,
I am using Alfresco's WCM Web Forms to receive input from users and render HTML using Freemarker. My question is how do I take advantage of Web Scripts to render dynamic information at render time?
I have a Web Form that asks the user to input a title and a document path, and the form renders a download link in HTML. I also want to automatically find the size of the selected document and render that next to the title. I've created a Web Script that takes the storeId and file path as input and outputs the file's size in HTML. The Web Script queries Alfresco using the avm.lookupStore and store.lookupNode functions.
If I run the web script by manually passing in the storeId and file path it works well. What I'm stuck on, is how I can call this Web Script from my Web Form to include in my Web Form output?
Thanks for any help!
I am using Alfresco's WCM Web Forms to receive input from users and render HTML using Freemarker. My question is how do I take advantage of Web Scripts to render dynamic information at render time?
I have a Web Form that asks the user to input a title and a document path, and the form renders a download link in HTML. I also want to automatically find the size of the selected document and render that next to the title. I've created a Web Script that takes the storeId and file path as input and outputs the file's size in HTML. The Web Script queries Alfresco using the avm.lookupStore and store.lookupNode functions.
If I run the web script by manually passing in the storeId and file path it works well. What I'm stuck on, is how I can call this Web Script from my Web Form to include in my Web Form output?
Thanks for any help!
Labels:
- Labels:
-
Archive
4 REPLIES 4

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2010 09:25 PM
Hi everyone,
Just wanted to update my progress on this issue:
Instead of trying to call my web script from my Freemarker file, I changed my Freemarker to directly access the Alfresco objects (bypassing the need for a web script at all). I tried some of the examples in the Freemarker Template cookbook http://wiki.alfresco.com/wiki/FreeMarker_Template_Cookbook, but I can't get access to the Alfresco objects through Freemarker as in the examples.
So for example, I've set up a web form with the following xsd and ftl:
test.xsd
test.ftl
I don't seem to have access to the Alfresco objects, like the examples do. The ${companyhome.properties.name} gives an error. If i remove it, the list of the company home children outputs nothing. I thought this could be an access issue due to the fact i've saved the web form in the Data Dictionary > Web Scripts folder rather than in the classpath, but I tried the latter and the result is the same.
Does anyone have any suggestions?
Thanks!
Just wanted to update my progress on this issue:
Instead of trying to call my web script from my Freemarker file, I changed my Freemarker to directly access the Alfresco objects (bypassing the need for a web script at all). I tried some of the examples in the Freemarker Template cookbook http://wiki.alfresco.com/wiki/FreeMarker_Template_Cookbook, but I can't get access to the Alfresco objects through Freemarker as in the examples.
So for example, I've set up a web form with the following xsd and ftl:
test.xsd
<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:si="http://www.alfresco.org/alfresco/simple" targetNamespace="http://www.alfresco.org/alfresco/simple" elementFormDefault="qualified"> <xs:element name="simple"> <xs:complexType> <xs:sequence> <xs:element name="string" type="xs:normalizedString"/> </xs:sequence> </xs:complexType> </xs:element></xs:schema>
test.ftl
<#ftl ns_prefixes={"D":"http://www.alfresco.org/alfresco/simple", "alf":"http://www.alfresco.org"}><html> <body> <#– from example cookbook –> <b>Company Home Space:</b> ${companyhome.properties.name} <#– Table of the Spaces in my Home Folder –> <#– Shows the large 32x32 pixel icon, and generates an external access servlet URL to the space –> <table> <b>One</b> <#list companyhome.children as child> <b>Two</b> <#if child.isContainer> <tr> <b>Three</b> <td><img src="${url.context}${child.icon32}"></td> <#assign ref=child.nodeRef> <#assign workspace=ref[0..ref?index_of("://")-1]> <#assign storenode=ref[ref?index_of("://")+3..]> <td><a href="${url.context}/navigate/showSpaceDetails/${workspace}/${storenode}"><b>${child.properties.name}</b></a> (${child.children?size})</td> </tr> </#if> </#list> </table> </body></html>
I don't seem to have access to the Alfresco objects, like the examples do. The ${companyhome.properties.name} gives an error. If i remove it, the list of the company home children outputs nothing. I thought this could be an access issue due to the fact i've saved the web form in the Data Dictionary > Web Scripts folder rather than in the classpath, but I tried the latter and the result is the same.
Does anyone have any suggestions?
Thanks!
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2010 04:42 AM
Hi Tara,
I'm having a similar issue. Can't seem to access 'space' in my freemarker template.
returns error :
Expression space is undefined
I'm having a similar issue. Can't seem to access 'space' in my freemarker template.
<table> <#list space.children as child> <#if child.isDocument> <tr><td>${child.properties.name}</td></tr> <#if child.mimetype = "text/plain"> <tr><td style='padding-left:16px'>${child.content}</td></tr> <#elseif child.mimetype = "image/jpeg"> <tr><td style='padding-left:16px'><img width=100 height=65 src="/alfresco${child.url}"><td></tr> </#if> </#if> </#list> </table>
returns error :
Expression space is undefined

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2010 03:31 AM
Hi,
Well, i havent worked out how to run web scripts from rendering templates, but I found out why i couldnt reference the Alfresco model. Only a subset of objects are available for WCM rendering templates:
http://wiki.alfresco.com/wiki/WCM_Forms_Rendering#Variables_and_Functions_exposed_to_Rendering_Engin...
Well, i havent worked out how to run web scripts from rendering templates, but I found out why i couldnt reference the Alfresco model. Only a subset of objects are available for WCM rendering templates:
http://wiki.alfresco.com/wiki/WCM_Forms_Rendering#Variables_and_Functions_exposed_to_Rendering_Engin...
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2010 09:03 AM
Just wondering if anyone has discovered if it's possible to call a WebScript from within the WCM rendering process?
