Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Comparative Display Technologies in Sakai Aaron Zeckoski [email protected] Creative Commons AttributionNonCommercial-ShareAlike 2.5 License Sakai Programmer's Café 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… 2 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 3 What games are there in town? http://java.sun.com/products/servlet/ http://jakarta.apache.org/velocity/ 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… 4 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 5 Code Snippet package 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 6 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 7 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 8 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 9 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/ 10 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> 11 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 12 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 13 Velocity Templates Final • Go for technologies that provide better separation between Code and UI • Used for the portal and many tools • Bottom line: You are better off not using this, only use this if you have existing apps and cannot rewrite them 14 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/ 15 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> 16 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 17 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 18 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 19 Java Server Faces Intro JSF • 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 URL: http://java.sun.com/javaee/javaserverfaces/ 20 Code Snippet JSF <%@ 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> 21 Java Server Faces + JSF • The second most used display technology in Sakai (after Velocity) – Used for a small number of apps (Gradebook, Assignments, etc…) • Integrates well with Sakai – As good as velocity – Faces and Oracle ADF Faces • Pretty good docs and books 22 Java Server Faces - JSF • 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 23 Java Server Faces Final JSF • 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 24 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/ 25 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> 26 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 improving rapidly – Internationalization – Accessibility / FLUID • Good docs and code samples available on the RSF Wiki 27 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 • Used in Sakai core – Page order helper, Polls, etc. – Sakai Contrib (evaluation, blogwow, etc.) • Small user community • Still in development (also a positive) 28 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 29 Summary JSF • • • • • No plain Servlets Velocity discouraged JSP ok for small stuff JSF is just bad RSF recommended 30 What about the others? • • • • Struts – UNISA has several tools using this Spring MVC – OSP using this with XSLT Wicket – UC Davis has done integration work JRuby/Rails – VT has done initial proof of concept • Maybe others? (PHP, Shale, etc.) • Caveat emptor – None to minimal community support – Widgets and helpers non-existent – Little example code • Don’t let that stop you though! 31 Questions? 32