L2 Web App Development Guest Lecture At University of Surrey 20/11/09

100 %
0 %
Information about L2 Web App Development Guest Lecture At University of Surrey 20/11/09

Published on November 23, 2009

Author: dbryant_uk

Source: slideshare.net


A guest lecture I presented to Level 2 Web Application Development students within the Department of Computing at the University of Surrey

L2: Web Application Development Direct Web Remoting (DWR): Ajax made easy… Daniel Bryant Department of Computing, FEPS (d.bryant@surrey.ac.uk) Tai-Dev Ltd, (daniel.bryant@tai-dev.co.uk)

Today’s roadmap... • My life story (in under 3 minutes)… • Quick review - so, what is Ajax? (Old school vs new school) • DWR Introduction Looking deeper into DWR (client-side/server-side) Implementation Demo (and debugging) • Quick case study – TriOpsis Ltd • DWR is awesome!! But are there any disadvantages? • Review

My life story (abridged)… • Studying at Surrey for 8 years BSc Computing and IT - Placement at DTI (now called BERR, DBIS etc. etc...) MSc Internet Computing • PhD Student within the Department of Computing Argumentation “how humans reason” Software Agents “mobile and/or intelligent code” • JEE, Web 2.0, J2ME & RDBMS Consultant Working freelance for the past 5 years Started Tai-Dev Ltd 1 year ago (http://tai-dev.blog.co.uk/) J2EE, JEE 5, JSE, J2ME Spring, Hibernate, MySQL, GlassFish v2 HTML, CSS, Javascript Prototype, Script.aculo.us, JQuery Direct Web Remoting (DWR)…

So, just what is Ajax? • “Asynchronous JavaScript and XML” “…group of interrelated web development techniques used for creating interactive web applications or rich Internet applications.” (Wikipedia, 2008) • Building block for “Web 2.0” applications Facebook, Google Mail and many more (auto-complete forms) • Applications can retrieve data from the server asynchronously in the background without interfering with the display and behaviour of the existing page No browser plugins (a’la Flash, Flex, SilverLight) • The use of JavaScript, XML, or its asynchronous use is not required…

Ajax - the old school way… Client Server http://java.sun.com/developer/technicalArticles/J2EE/AJAX

Old school, not so cool… • Client-side Browser incompatibilities (Microsoft, and then the rest of the world...) Long-winded Error prone Responsible for parsing return data, often XML-based Responsible for handling application errors (response codes?) Large amount of repeated “boiler plate” code • Server-side Create Servlets (no abstraction, and limited chance to allow design patterns) Construct XML document of data Responsible for “flattening” Objects and Collections Set content-type of return data manually Manual error handing (convert Exceptions into response codes?)

Introducing the alternatives… • JavaScript Libraries/Frameworks dojo, JQuery, Prototype Greatly simplify client-side code Not so helpful on server-side… • JSP Taglibs/JSF Components jMaki, Ajax4jsf Very easy to utilise Limited server-side configuration (majority of focus on existing widgets and services) • Proxy-based Frameworks Direct Web Remoting (DWR), Rajax Best of both worlds Language specific on backend (Java) • Tip: Always new stuff coming out – check blogs and news sites...

Direct Web Remoting (DWR) Overview • DWR allows easy implementation of Ajax functionality Homepage @ http://directwebremoting.org/ Open source JavaScript “client-side” Java “server-side” • Proxy-based framework Client-side code can call Java server-side methods as if they were local JavaScript functions. Converts or “marshalls” parameters and return variable to/from Java/JavaScript • DWR generates the intermediate code (“piping” or boilerplate code) • Also provides Utility classes

DWR in pictures Image from http://directwebremoting.org/dwr/overview/dwr

Client-side • Core components DWR JavaScript engine JavaScript “interface” definitions of remote methods JavaScript Object Notation (JSON) used instead of XML • Call Java methods as if local JavaScript functions Albeit with callbacks… • Hides browser incompatibilities (via “engine.js”) XMLHttpRequest Object Maps function calls to URLs • Converts or “marshalls” data Java ArrayLists into JavaScript arrays Java Objects into JavaScript object • Simplifies error-handling Maps Java Exceptions to JavaScript errors

Server-side • Core components DWR JAR Library Proxy generator DWRServlets • Easy framework configuration XML or Annotations (Java 5+) Care needed… • Not tied to writing Servlets Promotes good OO coding and design patterns • Simply expose (existing) Application Services Specify order and types of parameter Can return any type of Collection or Object Can utilise Spring, Struts, JSF…

Implementation in 5 (easy) steps… 1. Copy DWR Library files into project 2. Configure your existing framework to handle DWR requests 3. Create your Data Model (Business Objects) and Application Services 4. Inform DWR of these classes and their required exposure client-side 1. dwr.xml configuration file 2. Annotations (Java 5+) 5. Create your client-side functions

Handling http requests (web.xml)…. … <servlet> <servlet-name>dwr-invoker</servlet-name> <servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class> <init-param> <param-name>classes</param-name> <param-value> uk.ac.surrey.wappdev.appservices.FeedbackService, uk.ac.surrey.wappdev.model.FeedbackBean </param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>dwr-invoker</servlet-name> <url-pattern>/dwr/*</url-pattern> </servlet-mapping> …

Create the Model (Business Objects) package uk.ac.surrey.wappdev.model; import org.directwebremoting.annotations.DataTransferObject; import org.directwebremoting.annotations.RemoteProperty; @DataTransferObject public class FeedbackBean { @RemoteProperty private int id; @RemoteProperty private String feedbackValue; public FeedbackBean() { } public FeedbackBean(int id, String feedbackValue) { this.id = id; this.feedbackValue = feedbackValue; } //getter and setter defined here... …

Create your Application Services… package uk.ac.surrey.wappdev.appservices; import ... @RemoteProxy public class FeedbackService { @RemoteMethod public List<FeedbackBean> getFeedbackAvailable() { List<FeedbackBean> results = new ArrayList<FeedbackBean>(); for (int i = 0; i < 5; i++) { FeedbackBean fbBean = new FeedbackBean(i, "Feedback Value " + i); results.add(fbBean); } return results; } ... }

Create your client-side functions… package uk.ac.surrey.wappdev.appservices; <script src='dwr/interface/LocService.js'></script> import ... <script src='dwr/engine.js'></script> @RemoteProxy public class FeedbackService { <script> function updateFeedback() { @RemoteMethod //alert("updateFeedback()"); public List<FeedbackBean> getFeedbackAvailable() { List<FeedbackBean> results = FeedbackService.getFeedbackAvailable({ new ArrayList<FeedbackBean>(); callback:function(dataFromServer) { cbUpdateFeedback(dataFromServer); for (int i = 0; i < 5; i++) { }, FeedbackBean fbBean = new FeedbackBean(i, "Feedback errorHandler:function(errorString, exception) { Value " + i); alert("Error: " + errorString); results.add(fbBean); } } }); return results; } } ... } function cbUpdateFeedback(feedbackBeanList) { //alert("cbUpdateFeedback()"); for (var i = 0, l = feedbackBeanList.length; i < l; i++) { var option = document.createElement("option"); option.setAttribute("value",feedbackBeanList[i].id); var optText = document.createTextNode(feedbackBeanList[i].feedbackValue); option.appendChild(optText); document.getElementById("feedbackEl").appendChild(option); } } </script>

Lights, camera, action... (oh yes, and debugging) • Quick demo of slide material • Quick look at debugging Client-side – Firefox’s Firebug Server-side – Netbeans’ debugger • Tip: If you want to be a professional software developer debugging efficiently should become as natural as breathing… Not emphasized enough in teaching (but this is just my opinion) Probably a worthwhile skill for those final year projects as well…

Real world case study... TriOpsis Ltd • Highly innovative start-up company based at the Research Park (STC) • Check out www.triopsis.co.uk for more information • Experts in the emerging field of Visual Business Information • Specialising on ‘in the field’ data capture via mobile devices • Images and associated metadata reporting relevant to target customer

Real world case study... TriOpsis Ltd Screenshot of TriOpsis Flagship product – the ‘Asset Manager’ (implemented by yours truly!)

And finally… There are some disadvantages with DWR… • As with any framework that generates (blackbox) “piping” Sometimes difficult to know what is happening “in the pipe” • Potentially difficult to debug Spans across client and server domain Can use Netbeans debugger and FireFox’s Firebug • Maintaining http session information Hybrid of POSTed forms and Ajax • Can cause unexpectedly large amounts of http traffic Passing of complete object graphs (typically developer error ☺ ) • Potential security implications Exposing incorrect methods etc. Easy to pass sensitive data in plaintext (passwords etc.) without knowing

Conclusions • We know what Ajax is… • We examined old school/new school approaches to implementation • We learned that DWR is a “proxy-based” framework Providing (JavaScript) client and (Java) server-side Ajax support Allows exposure of Java model (BOs) and services DWR “handles the details”.. • We’ve seen how to implement DWR • We’ve had a look at an often undervalued skill – debugging • Seen real case study using this technology, TriOpsis, which is actively used within Industry • And we are always aware of potential disadvantages Beware of “black box” implementations… Security, session and http traffic

Thanks for your attention… • I’m happy to answer questions now or later... • If you want to know more about DWR or debugging ask for a lab session Sorry, but I can’t answer individual emails... • Feedback, comments, constructive criticism...

Add a comment

Related pages

University of Surrey - Guildford | Homepage

The University of Surrey is a leading university located within the county town of Guildford, ... Continuing Professional Development (CPD)
Read more

Accommodation Services - University of Surrey - Guildford

Guest Rooms. More Information. ... Continuing Professional Development (CPD) ... © University of Surrey, Guildford, Surrey, ...
Read more

Lecturer - Wikipedia, the free encyclopedia

... if a person at a UK university is a lecturer then they ... staff web pages use ... anyone who conducts lectures at a university or ...
Read more

Lecture - Wikipedia, the free encyclopedia

Lecture attendees at a software development conference. A lecture ... Many university courses relying on lectures supplement them with smaller discussion ...
Read more


Suosittelemme iCloudin käyttöön uusinta versiota Safarista, Firefoxista, Microsoft Edge tai Internet Explorerista.
Read more

Microsoft UK Developers

... who love the web and apps. ... once whilst delivering a guest lecture at Stafford University and then ... web development day from a Microsoft ...
Read more

Lecture Notes | Introduction to Programming in Java ...

This section provides the schedule of lecture ... Lecture notes files ... the teaching of almost all of MIT's subjects available on the Web, ...
Read more

University for Development Studies - Home

University for Development Studies Official WebSite ... UDS Accra Guest House; Academics. ... Senior Lecture and a Head of Department at the School of ...
Read more