Webscripts - maksudsharif/Armedia-Training-Module GitHub Wiki

#Webscripts

If you haven't completed Jeff Pott's tutorial on Behaviors, read and complete that before following along here.

Webscripts are a powerful way to quickly make use of the data created in the Alfresco repository and to use that data to display data or create data endpoints in the classic sense. Alfresco handles some of the logistics of creating an endpoint for you to use but you can create entire APIs through webscripts and not have to use Share at all to interact with Alfresco.

The 3 (or 4) things you need to create a webscript are:

  • Descriptor file (includes permissions, endpoint url structure, parameters)
  • Controller (this could be a js controller, java controller, or even both)
  • View (what the response of a request will be)

Again, Jeff Potts' tutorial does a great job explaining the ins and outs of creating and using webscripts. For the assignment you will extend the whitepapers.get webscript.

Things to Know

Freemarker and HTML

Alfresco makes use of Freemarker as the templating engine which allows you to dynamically change views based on controller logic. It is helpful to really understand some basic directives in Freemarker to make creating views much easier. Some helpful directives are: #if and #list.

Java Controllers and Spring Beans

Spring beans are very finicky when injecting services and especially for webscripts. Make sure when troubleshooting to always check that your Spring bean is actually correctly formatted. Common issues are:

  • nodeService instead of NodeService
  • Webscripts instead of Webscript

Assignments

technicalreports.get

Extend Jeff Potts' webscript to display whitepapers and instead display your own type or technicalreports

  • This will be a Java-backed webscript and so you need to have a Java class for controller
  • A descriptor that gives permission to the correct groups
  • A view similar to jpotts' webscript.

In the included code, examples are provided that will help you.