This session introduces the Spring Web Scripts and the Spring Surf framework describing how they are used to underpin the Alfresco Share user interface. As well as covering the basic concepts, this session will cover the history and future roadmap for the frameworks.
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
PLAT-8 Spring Web Scripts and Spring Surf
1. Spring Surf & Web Scripts!
Dave Draper – UI Engineer - @_DaveDraper!
2. History lesson...
2007
• Alfresco 2.0 introduces first REST API (early WebScripts concepts)!
• Alfresco 2.1 introduces WebScripts!
• REST framework, JSR-311 (Jax-RS) URI Index!
• Scriptable controllers (or backed by Spring Java Beans)!
• FreeMarker template output (or Java output stream)!
2008
• Alfresco Web Framework demo-ware (model objects, JSP, FTL)!
• Alfresco Page Render (WebScripts as components on a page)!
• Combined, productised and renamed to Surf!
• Alfresco Share 3.0, 3.1 – Alfresco collaboration and DM – modern
XHTML and Ajax based interface!
3. History lesson (cont)...
Early 2009
• Alfresco Share 3.2!
• First contact between Alfresco and Spring Source!
Late 2009
• Alfresco Surf and WebScripts integrated with Spring MVC!
• Alfresco Surf and WebScripts contributed as Spring Extension –
Spring WebScripts and Spring Surf!
• Alfresco Share 3.3 – refactored onto Spring WebScripts and Spring
Surf!!
2010
• 3 Milestones and RC1 release!
• Alfresco Share 3.4 – using SpringSurf RC1!
4. History lesson (cont)...
2011
• Alfresco Team!
• New extensibility capabilities added!
• Version 1.0.0 releases!
• Alfresco Share 4.0!
5. What Are WebScripts?
• Services bound to a URIs which respond to HTTP methods such as
GET, POST, PUT and DELETE!
• Support multiple formats (HTML, JSON & XML)!
• A framework for creating a REST API!
• Made up of descriptor, controller, properties, configuration and
presentation files!
6. Why Use Web Scripts?
• Rapid development (no server restarts)
• Separation of concerns (MVC)
• Localization
• Extensibility
• FreeMarker and JavaScript
7. But What Is Spring Surf ?
• An extension to Spring MVC
• A set of controllers, resolvers and views
• A way of breaking an HTML page into re-
usable composite parts
• An interface to the Alfresco Repository
• The framework that underpins Alfresco
Share
8. Example Spring Surf Objects
• Pages
• Template Instances
• Regions
• Chrome
• Components
• Sub-Components
9. Mistakes were made…
• Chrome
• Scopes
• No Component nesting
• 1-1 Region/Component binding
• Spring Roo
• Tools
• Difficult to match output to source
10. …but there is lots of good stuff !
• Themes
• Model Object stores (file system, classpath, remote,
etc)
• Presets / object creation
• URI templates
• Remote connections
• Authentication
• Extensibility
• Endlessly configurable
11. What can you do with it?
• Rapid web-tier view composition – Spring MVC View Resolver!
• FreeMarker, JSP, Groovy, PHP pages!
• WebScript, FTL, JSP, Groovy, PHP components!
• Simple JavaScript, Groovy controllers!
• Remote API – REST request/response processing!
• WebScripts – standalone REST API tier!
• Portlets!
12. What you SHOULD do with it?
• Customize Alfresco Share!
• Use WebScripts and FreeMarker!
• Use JavaScript controllers!
• Use Endpoints to contact an Alfresco Repository in standalone
applications!
15. Regions and Components
• Regions define location into which Components can
be bound
• Binding done through region-id, source-id and
scope
o Forced 1-1 bindings
o Flawed concept for Component switching
• Sub-Components introduced as a workaround
• Components SHOULD use ComponentType or
Processor but are “optimized” to use WebScript
URL
16. Remote API
• Connectors & Authenticators!
• XML configure access to “endpoints” – obtained by id!
• Access HTTP methods through JavaScript controller or Ajax via proxy
controller!
• Endpoints hide the URL stem from scripts – authentication encapsulated
by connectors and authenticators!
• Connect to multiple REST sources; alfresco, wiki, search!
17. Remote API – Example!
var conn = remote.connect("alfresco");
var json = conn.get("/api/products/" + args.filter);
if (json.status == 200)
{
// Create JavaScript objects from the response
var obj = eval('(' + json + ')');
if (obj)
{
// Perform processing on the js objects
// set results into the model for the template
model.results = somearray;
}
}
18. Model Object Stores
• Persisters – read model object definitions from classpath, WEB-
INF, JARs!
• Alfresco legacy locations and Spring “friendly” locations!
o Migration of Alfresco Surf 3.2 apps!
o New locations require less files, folders!
• Read and write to remote location and local file system!
• Example - Alfresco Share stores pages and components for
dynamic dashboards in the repository!
19. Component .head.ftl template!
• Allow WebScripts to add JavaScript and CSS dependencies into
HTML <head>
• Use ${head} in Template Instance to output dependencies into
<head>
• Use <@script> to automatically switch between .js and –min.js
<link rel="stylesheet" type="text/css" href="${page.url.context}/
products/products.css" />
<script src="${page.url.context}/products/products.js"></script>
20. Useful Runtime Tools
• /service/index
o Browse WebScripts
o WebScript refresh
o SurfBug toggle
21. Roadmap
• Forking from Spring back into Alfresco!
• Continued development (more extensibility features, performance
improvements)!
• Continued use in Alfresco projects!
• More blogging, forums and documentation!
22. How do I use it?
• You CAN SVN checkout, maven build:
https://src.springframework.org/svn/se-surf/trunk!
• You SHOULD use Alfresco Community JARs when available!