Post on 02-Nov-2014
description
transcript
Creative Commons Attribution-ShareAlike 2.5 License Sakai Programmer's Café
Sakai Oxford Tetra ELF Workshop
Comparative Display Technologies in Sakai
Aaron Zeckoskiaaronz@vt.edu
2
What do we want out of a display technology?
• Easy to use for the developer
• Good separation of Code and UI–i.e. easy to use for the UI designer
• Good integration with Sakai–Portal, widgets, tools, etc…
3
What technologies work
• Virtually any Java related display technology can work in Sakai
• There are some caveats– Sakai uses a special Servlet to handle redirects
and processing of HTTP request variables– Portal and widget interaction have to be developed
for each technology
• Bottom line: You are better off sticking with the ones that currently work
4
What games are there in town?
http://jakarta.apache.org/velocity/
http://java.sun.com/products/servlet/
http://java.sun.com/products/jsp/
JSF http://java.sun.com/javaee/javaserverfaces/
http://www2.caret.cam.ac.uk/rsfwiki/
But there are a few things to consider…
5
Java Servlets Intro
• modules of Java code that run in a server app to answer client requests
• HTML is hardcoded in the Java class– It can be pulled from external files though
• Most more advanced technologies are built on Servlets
• Sakai uses Servlet API 2.4
URL: http://en.wikipedia.org/wiki/Java_Servlet
6
Code Snippetpackage org.java.helloworld;
import java.io.*;import javax.servlet.*;import javax.servlet.http.*;
public class HelloWorld extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); out.println("Hello World"); }}
URL: http://www.apl.jhu.edu/~hall/java/Servlet-Tutorial/Servlet-Tutorial-First-Servlets.html
7
Java Servlets +
• Tried and tested technology (1997)
• Runs on the server instead of on the client like an applet
• Pure Java code
• Session tracking via HttpServlet
• Works fine in Sakai– Café Servlet Hello World sample code
8
Java Servlets -
• Invented in 1997 for goodness sake!
• HTML is placed in the Java class
• Impossible for UI designers to work with
• Poor separation of UI and Code
• Development this way is painful and slow compared to more modern methods
9
Java Servlets Final
• Why would you want to write pure Servlets any more considering the many better options out there?
• You are going to use Servlets anyway but at least use something along with it
• Bottom line: Don’t use this unless you just want to put an existing Servlet app into Sakai
10
Velocity Templates Intro
• Java based template engine
• Uses “references” to place dynamic content in html pages with # or $ vars– Somewhat similar to PHP or JSP
• Meant to allow UI designers to work alongside programmers
• Apache project
URL: http://jakarta.apache.org/velocity/
11
Code Snippet<HTML>
<HEAD><title>Velocity Sample</title></HEAD><BODY><h1>Hello $user.name</h1><table>
#foreach( $item in $items )#if ( $itemCheck($item) )<tr>
<td> $item.value </td></tr>#end
#end </table></BODY></HTML>
12
Velocity Templates +
• Uses “references” to place dynamic content in html template pages– Somewhat similar to PHP or JSP
• Most used display technology in Sakai– Integration with Sakai is good
• Ok separation of UI and Code
• Decent docs and community
13
Velocity Templates -
• The current Velocity implementation in Sakai is a custom and out of date version
• Integration with Sakai is OK but not really being worked on much anymore
• New development in Velocity is discouraged by the community
• Mostly carried over from CHEF
14
Velocity Templates Final
• Go for technologies that provide better separation between Code and UI
• Bottom line: You are better off not using this, only use this if you have existing apps and cannot rewrite them
15
Java Server Pages Intro
• Dynamic Java web content scripting language– Very similar to PHP
• JSP pages are compiled into Servlets when accessed
• Pages are a mixture of HTML, taglib tags, and Code
URL: http://java.sun.com/products/jsp/
16
Code Snippet<HTML>
<HEAD><title>JSP Sample</title></HEAD><BODY><h1>Hello <%= user.getName() %></h1>Today is <%= new Date() %><br/><ul><% for (int i=0; i<items.size(); i++) { %>
<li><%= ((Item)items.get(i)).getValue() %></li><% } %></ul></BODY></HTML>
17
Java Server Pages +
• Easy to develop in and work with• Can be changed without restarting• Works fairly well in Sakai
– JSP support is available via a cool Servlet by Andrew Thornton (Cambridge)
– Used in Rwiki (sorta), XML version
• Well tested technology with large community
• Excellent docs and many books
18
Java Server Pages -
• Mixes code and HTML together– Poor separation of code and UI design
• Compiled when accessed– This can cause a noticeable delay when
accessing a page for the first time
• Integration with Sakai is poor• Has many of the same weaknesses that
other scripting languages have
19
Java Server Pages Final
• JSP support in Sakai is not great yet
• It is difficult for UI designers
• Bottom line: Use this if you have existing JSP code, but go for options that provider better separation between UI and Code for new projects
20
Java Server Faces Intro• A Java based set of APIs for managing
state, handling events, and defining navigation
• Mostly builds on JSP– Though it can be used without JSPs
• Includes a custom set of tag libraries• Includes error handling, input validation,
and internationalization support
JSF
URL: http://java.sun.com/javaee/javaserverfaces/
21
Code Snippet<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %><%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %><html><head><title>JSF sample</title></head><body> <f:view> <h1><h:outputText value=“Hello #{user.name}"/></h1> <h:dataTable id=“items" value="#{itemsBean.items}" var=“item"> <h:column> <h:outputText value="#{item.value}" /> </h:column> </h:dataTable> </f:view></body></html>
JSF
22
Java Server Faces +• The second most used display
technology in Sakai (after Velocity)– Used for the portal and a small number of
apps (Gradebook, Assignments, etc…)
• Integrates well with Sakai– better than any of the other current solutions
(for now)
• MyFaces and Oracle ADF Faces• Pretty good docs and books
JSF
23
Java Server Faces -• Pretty heavyweight and has problems in
the current version– These might be fixed in the upcoming
version• Poor separation of UI design and code• High learning curve• Difficult to use and not very flexible• Poor AJAX/Javascript integration• Does not work with browser navigation
JSF
24
Java Server Faces Final• Most new apps in Sakai are written in
this but it is recognized as having many weaknesses
• High learning curve and difficulty of use means slow development
• Bottom line: Don’t use this unless you really have to, even if you have existing code
JSF
25
Reasonable Server Faces
• Spring based web programming framework
• Uses pure XHTML templates, clean separation of UI and Code
• Lightweight and pure bean programming
• Works well with AJAX and Javascript
URL: http://jakarta.apache.org/velocity/
26
Code Snippet<html><head><title>RSF sample</title></head><body>
<h1>Hello <span rsf:id=“user-name”>User Name</span></h1>Today is <span rsf:id=“current-date”>1/1/2006</span><br/><table> <tr rsf:id=“items:”> <td rsf:id=“item-value”>item value here</td> </tr></table>
</body></html>
27
Reasonable Server Faces +• Uses pure XHTML templates
– Provides clean separation of UI and Code
• Respects the HTTP request cycle– Back button works!
• Works well with AJAX and Javascript
• Sakai integration and features are improving rapidly
• Good docs and code samples available on the RSF Wiki
28
Reasonable Server Faces -
• Greater separation of UI and code can require more files and lines of code– This is true of other solutions as well
• Not used in Sakai core yet but is fully functional in it and integrates somewhat– Some code in Sakai Contrib (rsf gallery)
• Small user community• Still in development (also a positive)
29
Reasonable Server Faces Final
• The only really good separation of UI design and Code available
• Community support is growing and Sakai integration improving
• Bottom line: Use of this is recommended for new Sakai apps
30
Summary
JSF
• No plain Servlets
• Velocity discouraged
• JSP ok for small stuff
• JSF is just bad
• RSF recommended