Presentation is loading. Please wait.

Presentation is loading. Please wait.

Creative Commons Attribution- NonCommercial-ShareAlike 2.5 License Sakai Programmers’ Café Sakai NWU Workshop, South Africa Spring Fundamentals & RSF Fundamentals.

Similar presentations


Presentation on theme: "Creative Commons Attribution- NonCommercial-ShareAlike 2.5 License Sakai Programmers’ Café Sakai NWU Workshop, South Africa Spring Fundamentals & RSF Fundamentals."— Presentation transcript:

1 Creative Commons Attribution- NonCommercial-ShareAlike 2.5 License Sakai Programmers’ Café Sakai NWU Workshop, South Africa Spring Fundamentals & RSF Fundamentals Antranig Basman antranig@caret.cam.ac.uk

2 2 The Spring Framework The most significant development in programming in 10 years Will only have a lightning tour in this session Crucial since –Is used throughout Sakai as a service location framework –Is the basis for the RSF presentation framework we will be using for tool development Is extensively used in the wider world as a Java “enterprise” technology Purpose is to organise and orchestrate the different parts of an application, which are packaged as “beans”

3 3 What is so important about Spring? Somewhat hard to convey without seeing it! Spring is the first “negative technology”, that as well as staying invisible in your code, also works hard to hide dependencies on other technologies as well Solidly separates code from configuration, making it easy to work with extremely large applications without getting lost/in a tangle Helps you think properly about smaller applications too! Is a deeper idea than it appears, that you will need a bit of time to settle into

4 4 Java Beans and Spring Beans have been with us since the beginning of Java (1996 and beyond) Almost a non-concept – a bean is a simple Java object with “getters and setters” Spring concept of a bean is not very much more loaded – however it is imagined that each bean “does some work” Setters in Spring are generally much more important than getters In Spring, a Setter is used to deliver a dependency public class MyBean { private String property; public void setProperty(String property) { this.property = property; } public String getProperty() { return property; }

5 5 A Simple Spring Bean Notes: –The whole point of Spring is not to see it –Spring isn’t just about service location, but it is one (common) way to use it public class WorkerBean { private UsefulService myService; public void setMyService(UsefulService myService) { this.myService = myService; } public int doMyWork(int argument) { int result = myService.invoke(argument); return result + 3; } Setter method marks this as a bean - The dependency on myService is injected The bean’s business method (work for its clients) is defined here

6 6 Spring Configuration for the bean Notes: –The “id” attribute is optional, but typically supplied since you usually want to refer to the bean again –You can “keep on going”, building a deeper and deeper tree of clients and dependencies –The ultimate endpoint of a mature Spring design is to have the entire application structure in Spring (still a controversial view!) –The use of Spring in Sakai is typically much “thinner” – there is ONE clear API/Impl boundary across the server.... Injection here delivers the bean “myService” to the setter on the client

7 7 Typical Spring usages The Spring configuration is typically written in an XML file, defining an Application Context –Recent support for configuration through Java 5 Annotations, but this defeats the whole point! Special support for loading in a Servlet environment, creating a WebApplicationContext from a file by default named applicationContext.xml –Initialised on context startup using Servlet Listeners defined in web.xml Can also use Spring completely “headless” by creating the application context by hand –Will see an example tomorrow morning

8 8 Sakai Services in Spring Sakai APIs are defined in terms of Java interfaces There is ONE implementation of each API interface in Sakai The name of the Spring bean in the Sakai Spring context (file components.xml ) is always the fully qualified interface name Classic example: the Sakai UserDirectoryService Lots more stuff here! Will learn about this later, but concentrate on the familiar elements and There is ONE global, shared Sakai application context holding beans for all Sakai services <bean id="org.sakaiproject.user.api.UserDirectoryService“ class="org.sakaiproject.user.impl.DbUserService" init-method="init"destroy-method="destroy" singleton="true">......

9 9 Sakai UserDirectoryService in code To use this API in your bean, you would write a setter which accepted a UserDirectoryService object, and then set up the injection in a Spring XML file package org.sakaiproject.user.api;.... /** * UserDirectoryService manages the end-user modeling for Sakai. * */ public interface UserDirectoryService extends EntityProducer {.... User getUser(String id) throws UserNotDefinedException;... }

10 10 RSF

11 11 Why RSF? RSF was designed with several special requirements of the Sakai community (and other similar communities) in mind –The first key point is to decouple the workflows of developers and designers/UX experts, and allow them to work independently –The second key point is to enable universal portability of apps to whatever environments may arise, without requiring code changes (today, to Servlets, Sakai, and JSR-168 Portlets, tomorrow to JSR-286 or the final “containerless” liberation) RSF is closely involved with the FLUID “Flexible UI” project now starting up at UToronto

12 12 RSF for coders and designers RSF is fun for coders since it is built out of Spring components –Can always break open the framework in an emergency –Once you get the pattern, it is really obvious how to build very powerful components and apps that require a lot more custom/stovepipe work in other frameworks RSF is fun for designers since they can just work with plain HTML and hand it over the fence to coders who can start working with it directly

13 13 Today’s talk A lightning tour of the basics, with enough “bootstrap” info about RSF fundamentals to let you understand and work with basic apps, and tackle the exercise after the break More thorough introduction and survey tomorrow

14 14 Let’s get started! Here is some real HTML: It is also an RSF template! –To make a template, you simply add the rsf:id attribute to tags which might have their content replaced when the app runs, or might need to be copied or moved about RSF sample Hello User Name Today is 1/1/2006 item value here

15 15 RSF Templates The template will load and render fine in any browser or editor –Properly, we will always give RSF templates a proper XHTML doctype, and namespace for the rsf:id attribute –The rsf:id attribute is the ONLY addition to the schema –RSF can actually render with any kind of XML template, not just XHTML <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

16 16 Using the Template Everything in RSF is a Spring-configured bean of some kind A special kind of bean called a Producer (or View Producer) is responsible for rendering a page from a template –The same Producer can render from many different templates, as long as the rsf:ids agree The purpose of a Producer is to create a Component Tree of RSF “Primitive Components” which will get paired up with the template by the RSF renderer (IKAT)

17 17 View Producer Java code (a Spring bean) which defines what appears in the view UIOutput and UIBranchContainer are primitive RSF components The 2 nd arguments to the make() calls match up with the rsf:ids written in the template public class ItemsProducer implements ViewComponentProducer, DefaultView {... private CrudPlusLogic logic; public void setLogic(CrudPlusLogic logic) { this.logic = logic; } public void fillComponents(UIContainer tofill, ViewParameters viewparams, ComponentChecker checker) { UIOutput.make(tofill, "user-name", logic.getUserName()); for (CrudPlusItem item: logic.getAllVisibleItems().iterator()) { UIBranchContainer itemrow = UIBranchContainer.make(listform, "item-row:", item.getId()); UIOutput.make(itemrow, “item-value”, item.getValue()); } UIOutput.make(itemrow, “current-date", new Date().toString() ); }

18 18 RSF rendering basics UIOutput – will pair up with ANY tag in the markup. The 3 rd argument will replace the body of the tag. –rsf:id must not have a colon UIBranchContainer – will also pair up with any tag. Represents a “branch point” in the rendering where a tag will be copied out again, missed out completely, or rendered out of order. –rsf:id must have a colon Full details on all the RSF primitive components (like UILink, UIForm, UICommand) on the RSF wiki at http://www2.caret.cam.ac.uk/rsfwiki/Wiki.jsp?page=PrimitiveComponents http://www2.caret.cam.ac.uk/rsfwiki/Wiki.jsp?page=PrimitiveComponents

19 19 Registering a Producer Spring beans typically live as long as the entire application (application scope) RSF extends Spring with a fast request-scope implementation, RSAC RSF Producers are typically declared as Spring beans at request scope Request-scope beans go into requestContext.xml rather than applicationContext.xml, but the file format is the same You can refer to any application-scope beans (including Sakai services) directly as dependencies of your request-scope beans

20 20 Registration of the ItemsView In WEB-INF/requestContext.xml: Typically no need for an id since RSF detects and loads up producers by itself The one dependency is a bean representing a Sakai API (service implementation) – not only at application scope but in the shared area. <property name="logic" ref="org.sakaiproject.crudplus.logic.CrudPlusLogic" />

21 21 The Scene This is enough “bootstrap” info about RSF basics to let you understand and work with basic apps, and tackle the exercise after the break More thorough introduction and survey tomorrow

22 22 Questions? RSF wiki, forums and JIRA –http://www2.caret.cam.ac.uk/rsfwikihttp://www2.caret.cam.ac.uk/rsfwiki Spring framework –http://www.springframework.org/http://www.springframework.org/

23 23 The Scene Having set the scene with some general theory and background, we are set to continue after lunch with tackling some practical Sakai development


Download ppt "Creative Commons Attribution- NonCommercial-ShareAlike 2.5 License Sakai Programmers’ Café Sakai NWU Workshop, South Africa Spring Fundamentals & RSF Fundamentals."

Similar presentations


Ads by Google