As we transition to the new Hyland Community, some post links may be temporarily disrupted as we finalize redirects. We apologize for the inconvenience and are working to resolve this as quickly as possible. Details.
WEB-INF\lib
shared\classes\alfresco\extension
<webscript> <shortname> Hello World </shortname> <description> Hello World Web Script </description> <url> /helloworld?name={nameArgument} </url> </webscript>
package com.helloworld.scripts; import java.util.Map; import java.util.HashMap; import org.alfresco.web.scripts.DeclarativeWebScript; import org.alfresco.web.scripts.WebScriptRequest; import org.alfresco.web.scripts.WebScriptStatus; public class HelloWorld extends org.alfresco.web.scripts.DeclarativeWebScript { String nm=""; protected Map<String, Object> executeImpl(WebScriptRequest wr, WebScriptStatus ws){ System.out.println("from executeImpl()****************"); System.out.println("hello****************"); Map<String, Object> model = new HashMap<String, Object>(); model.put("foo", nm); return model; } public void setSomeName(String name){ nm=name; } }
<?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans-2.0.dtd'> <beans> <bean id="webscript.com.scripts.helloworld.get" class="com.helloworld.scripts.HelloWorld" parent="webscript"> <property name="someName"> <value> This is a Foo Name </value> </property> </bean> </beans>
<html> <body> <p> Hello, ${args.name} </p> Foo : ${foo} </body> </html>
It is really quite powerfull and easy to do once you have it setup.There are a few items you must be aware of. Here's how I did it.* Create the javabean according to java standards.* Add the javabean to the freemarker model. I did this by creating my own servlet the extended GuestTemplateContentServlet and extending the buildModel method. This method is what is used by alfresco add the alfresco java beans to the root model. * I then added my own javabeans that did whatever I needed them to.So for example you had a Javabean with a getTotal() method and you added it to the HashMap with an id of "calc". In the template you would simply say: ${calc.total} once the javabean is added to the root Hashmap. Take a look at the org.alfresco.web.app.servlet.GuestTemplateContentServlet. Turn on it's debugging in you wish and you will see how it works.The total method can return most any java.lang data type as well as List or Map interfaces.