SlideShare ist ein Scribd-Unternehmen logo
1 von 84
Downloaden Sie, um offline zu lesen
Ajax on Struts:
Coding an Ajax Application with Struts 2
 Wednesday, October 1st, 2:35p-3:35p
             Ted Husted
 In this session, we explore
     How to integrate an Ajax UI framework with a
     Struts 2 business framework.
     Business services Struts can provide to an Ajax UI,
     Basics of the Struts 2 web application framework.
     Basics of the Yahoo User Interface Library (YUI).
Ajax on Struts:
Coding an Ajax Application with Struts 2




                       Square One University Series
Ajax on Struts

For the latest version of this presentation,
visit http://slideshare.com/ted.husted
For the latest version of source code,
visit http://code.google.com/p/yazaar/
Abstract

Ajax is the web's hottest user interface.
Struts is Java's most popular web
framework. What happens when we put
Ajax on Struts?
During the session, we will cover
  Integrating an Ajax UI with Struts 2
  Using Yahoo User Interface (YUI) Library
  Using Struts to provide services to Ajax UI
Ajax on Struts
What are Ajax widgets?
What are we coding?
Is there an Ajax architecture?
How can we switch to server-side data?
What about error-handling?
Ajax on Struts
What are Ajax widgets?
What are we coding?
Is there an Ajax architecture?
How can we switch to server-side data?
What about error-handling?
What are Ajax widgets?
Ajax lets scripts make requests and
update content without a page refresh
Widgets are “black-box” user interfrace
(UI) components
Typically, widgets are configured without
touching the component's internals
DataGrids, Calendars, Carousels, even
TextBoxes
What are Ajax widgets?
Widgets can be used with any server platform
   PHP, Java, .NET, Ruby, Python
Client-side widget provides UI
Server-side technology provides data access
and business logic
What is Apache Struts?
Free open-source framework for creating
Java web applications
Provides three major components
  Request handler
  Response handler
  Tag libraries for JSP, as well as
  Freemarker, and Velocity
Can we use Ajax with a Struts
        application?
XHR is just another request/response
Struts can stream data as a response
Use JSP scriptlets
Use Ajax JSP tag libraries
Use plain-vanilla Ajax libraries
Why use Apache Struts?
Mature, well-supported, well-understood
Provides input validation and data conversion
Interacts well with Spring, Hibernate, et al
Defacto standard for Java web applications
Where do we start?
Case study
  Pure Ajax prototype
  Test data encapsulated as JSON
  Later, replace test data with JSON via XHR
Use “spikes” to separates concerns
How do we select an Ajax library?
 Submit before you commit
 Code your own sample application
 Pick the one that works for you and
 yours
 We tried Dojo and YUI
http://dojotoolkit.org/
http://developer.yahoo.com/yui/
Why Yahoo User Interface
      (YUI) Library?
Well documented and supported
Lots of working examples
New BSD license
Easy to read code
Easy to hack code
Ajax on Struts
What are Ajax widgets?
What are we coding?
Is there an Ajax architecture?
How can we switch to server-side daa?
What about error-handling?
What did we code?
1 Provide a list of employees.
2 Record employee's first name, last name,
extension, username, hire date, and hours
worked per week.
3 Allow list to be filtered by first name, last
name, or username.
4 Allow full or filtered list to be sorted by any
field.
5 Allow record to be updated by authorized
users
What did we code?
Use YUI DataTable to display list
Share DataTable record with data-entry
form
 Use TabView to separate list and edit
What are we going to code?
Prototype with static data
Request data from Struts 2 Action
  Use Struts 2 Plugin to return JSON
How does the Struts 2
          JSON plugin work?
    Exposes action properties as fields in a
    JSON record.
{
    stringValue : quot;A string valuequot;,
    intArray: [10, 20],
    map: {
        Zaphod : quot;Just this guy, you knowquot;,
        Arthur : quot;Monkey-boyquot;
    },
    record: quot;start a named recordquot;
}
public class ExampleOutputAction {

   private String stringValue = quot;A string valuequot;;
   public String getStringValue() {
       return stringValue;
   }
   public void setStringValue(String value) {
       stringValue = value;
   }

   private int[] intArray = {10, 20};
   public int[] getIntArray() {
       return intArray;
   }
   public void setIntArray(int[] value) {
       intArray = value;
   }

   private Map map = new HashMap();
   public Map getMap() {
       return map;
   }
   public void setMap(Map value) {
       map = value;
   }
private String nextRecord = quot;start a named recordquot;;
    @JSON(name=quot;recordquot;)
    public String getNextRecord() {
        return nextRecord;
    }

    //'transient' fields are not serialized
    @SuppressWarnings(quot;unusedquot;)
    private transient String stayHome;

    //fields without getter method are not serialized
    @SuppressWarnings(quot;unusedquot;)
    private String noGetterForMe;

    public String execute() {
        map.put(quot;Zaphodquot;, quot;Just this guy, you knowquot;);
        map.put(quot;Arthurquot;, quot;Monkey-Boyquot;);
        return quot;successquot;;
    }
}
{
    quot;intArrayquot;:[10,20],
     quot;mapquot;: { quot;Arthurquot;: quot;Monkey-Boyquot;,
              quot;Zaphodquot;:quot;Just this guy, you knowquot;},
     quot;recordquot;:quot;start a named recordquot;,
     quot;stringValuequot;:quot;A string valuequot;
}

{
    stringValue : quot;A string valuequot;,
    intArray: [10, 20],
    map: {
        Zaphod : quot;Just this guy, you knowquot;,
        Arthur : quot;Monkey-boyquot;
    },
    record: quot;start a named recordquot;
}
package actions;

import   java.util.Map;
import   java.util.HashMap;
import   com.googlecode.jsonplugin.annotations.JSON;
import   org.texturemedia.smarturls.ParentPackage;
import   org.texturemedia.smarturls.Result;

@ParentPackage(quot;json-defaultquot;)
@Result(name=quot;successquot;, type=quot;jsonquot;, location=quot;quot;)
public class ExampleOutputAction {

    private String stringValue = quot;A string valuequot;;

    // ...
How did we code a UI using
       static data?
Entry list
Entry form
List shares data with form
Ajax on Struts
What are Ajax widgets?
What are we coding?
Is there an Ajax architecture?
How can we switch to server-side data?
What about error-handling?
Is there an Ajax architecture?
<script src=quot;my.jsquot; type=quot;text/javascriptquot;>


if (typeof parent.my != quot;undefinedquot;) {
    var my = parent.my; // application namespace
} else {
    var my = {};
    var my.oEvent = {

   // ... instantiate rest of my
Is there an Ajax architecture?
<script src=quot;contacts.jsquot; type=quot;text/javascriptquot;>
</script>



my.Contacts = function(){
  my.Contacts.superclass.constructor.call(this);
};
YAHOO.lang.extend(my.Contacts,YAHOO.yazaar.flev-base);
What's a FLEV widget?
Common business workflow is
  Find / List / Edit / View
  Or quot;FLEVquot;
The FLEV widget defines one columnset
and datasource to use with all four
presentations
MY.Contact.prototype.oColumnHeaders = [
{key:quot;first_namequot;, text:quot;First Namequot;,
sortable:true, resizeable:true,
editor:quot;textboxquot;, formClassName: quot;requiredquot;,
formTitle: quot;Enter employee's first namequot;},

// more entries

];

     key and text are shared attributes
     sortable, resizable are List attribute
     formClassName, formtitle are Edit
     attributes (validation)
MY.Contact.prototype.oResponseSchema = {
fields:[quot;idquot;, quot;last_namequot;, quot;first_namequot;,
quot;extensionquot;, quot;usernamequot;, quot;hiredquot;, quot;hoursquot;,
quot;editorquot;]
};



MY.Contact.prototype.LOCAL_DATA = {
 result : [{id: 'c5b6bbb1-66d6-49cb-9db6-
743af6627828', last_name: 'Beeblebrox ',
first_name: 'Zaphod ', extension: '555-123-
4565', username: 'zaphie ', hired:
'04/01/1978', hours: -1, editor: '1'},
 // ...
];
my.oEvent.createEvent(quot;contactLoadquot;)

my.oEvent.onContactLoadReturn = function(oData)
{
 my.info(quot;Firing contactLoad Eventquot;);
 my.oEvent.fireEvent(quot;contactLoadquot;, oData);
};
<script type=quot;text/javascriptquot;>
 var onContentReady = function() {
  _Contact = new MY.Contact();
  my.oEvent.subscribe(quot;contactLoadquot;,_Contact.load,
   _Contact);
  my.oEvent.onContactLoadReturn(_Contact.LOCAL_DATA);
 };
 YAHOO.util.Event.onContentReady(quot;elBodyquot;,
  onContentReady);
</script>
Ajax on Struts
What are Ajax widgets?
What are we coding?
Is there an Ajax architecture?
How can we switch to server-side data?
What about error-handling?
How can we switch over to
    server-side data?
Create an example Action that returns
example data
Create a database Action that returns
persistent data
public class ContactLoadAction {
private List contactLoad = new ArrayList();
@JSON(name=quot;resultquot;)
public List getContactLoad() {
  contactLoad.add(new Contact(
    quot;c5b6bbb1-66d6-49cb-9db6-743af6627828quot;,
    quot;Beeblebroxquot;,
    quot;Zaphodquot;,
    quot;555-123-4565quot;,
    quot;zaphiequot;,
    quot;04/01/1978quot;,
    quot;-1quot;,
    quot;1quot;
  ));
  // ...
  return contacts;
}
public class Contact {

public Contact() {};

public Contact(String id, String last_name, String first_name,
String extension, String username, String hired, String hours,
String editor) {
 setId(id);
 setLast_name(last_name);
 setFirst_name(first_name);
 setExtension(extension);
 setUsername(username);
 setHired(new Date(hired));
 setHours(new Double(hours));
  setEditor(editor);
}

private String id;
public void setId(String value) {
  id = value;
}
public String getId() {
  return id;
}

// more properties ...
How can we switch over to
      server-side data?
Action data:
{quot;resultquot;:[{quot;editorquot;:quot;1quot;,quot;extensionquot;:quot;555-123-
4565quot;,quot;first_namequot;:quot;Zaphod quot;, ...
]}

JavaScript data:
my.Contact.prototype.LOCAL_DATA =
{result:[{id: 'c5b6bbb1-66d6-49cb-9db6-
743af6627828', last_name: 'Beeblebrox ', first_name:
'Zaphod ' ...
http://developer.yahoo.com/yui/connection/
<script>
var transaction = YAHOO.util.Connect.asyncRequest(
    'POST', sUrl, callback, null);
</script>

var callback =
{
  success: function(o) {/*success handler code*/},
  failure: function(o) {/*failure handler code*/},
  argument: [argument1, argument2, argument3]
}

var responseSuccess = function(o){
/* Please see the Success Case section for more
 * details on the response object's properties.
 * o.tId
 * o.status
 * o.statusText
 * o.getResponseHeader[ ]
 * o.getAllResponseHeaders
 * o.responseText
 * o.responseXML
 * o.argument
 */
};
// my.oEvents.onContactLoadReturn(_Self.LOCAL_DATA);
YAHOO.util.Connect.asyncRequest('POST', quot;contact-
load.doquot;, callback, null);

var callback = {
    success : function(o) {
        my.oEvent.onContactLoadReturn(o.responseText);
    }
};
{quot;resultquot;:[
    {quot;editorquot;:quot;1quot;,quot;extensionquot;:quot;555-123-
4565quot;,quot;first_namequot;:quot;Zaphod quot;, ...
]}

my.Contact.prototype.LOCAL_DATA =
{result:[
// my.oEvents.onContactLoadReturn(_Self.LOCAL_DATA);
YAHOO.util.Connect.asyncRequest('GET', quot;contact-load.doquot;,
callback, null);

var callback = {
    success : function(o) {
      var payload = eval(quot;(quot; + o.responseText + quot;)quot;);
      my.oEvent.onContactLoadReturn(payload);
    }
};

- var payload = eval(quot;(quot; + o.responseText + quot;)quot;) ;
+ var payload = jcontext.parseJSON(o.responseText);




                                     http://json.org/json.js
What about JavaScript Hijacking?
/* {quot;resultquot;:[{quot;editorquot;:quot;1quot;,quot;extensionquot;:quot;555-123-4565quot;,
...
}]} */

var data = o.responseText;
var payload =
eval(quot;(quot;+data.substring(data.indexOf(quot;/*quot;)+2,
    data.lastIndexOf(quot;*/quot;))+quot;)quot;);
my.oEvent.onContactLoadReturn(payload);
What about JavaScript Hijacking?
<package name=quot;my-defaultquot; extends=quot;json-defaultquot;>
 <result-types>
  <result-type name=quot;jsonquot;
   class=quot;com.googlecode.jsonplugin.JSONResultquot;
   default=quot;truequot;>
   <param name=quot;wrapWithCommentsquot;>true</param>
  </result-type>
 </result-types>

 <action name=quot;contact-loadquot;
  class=quot;actions.ContactLoadActionquot;>
  <result />
 </action>
</package>
Ajax on Struts
What are Ajax widgets?
What are we coding?
Is there an Ajax architecture?
How can we switch to server-side data?
What about error-handling?
What about error handling?
var callback = {
  success : function(o) {
    var payload = eval(quot;(quot; + o.responseText + quot;)quot;);
    my.oEvent.onContactLoadReturn(payload);
  }
};

YAHOO.util.Connect.asyncRequest('POST', quot;contact-
load.doquot;, callback, null);
What about error handling?
var callback =
{
  success: function(o) {/*success handler code*/},
  failure: function(o) {/*failure handler code*/},
  argument: [argument1, argument2, argument3]
}
How does JSON-RPC handle errors?
{
    quot;versionquot; : quot;1.1quot;,
    quot;errorquot; : {
      quot;namequot; : quot;JSONRPCErrorquot;,
      quot;codequot; : 123,
      quot;messagequot; : quot;An error occurred parsing the request object.quot;,
      quot;errorquot; : {
         quot;namequot; : quot;JSONErrorquot;,
         quot;messagequot; : quot;Bad arrayquot;,
         quot;atquot; : 42,
         quot;textquot; : quot;{quot;idquot;:1,quot;methodquot;:quot;sumquot;,quot;paramsquot;:[1,2,3,4,5}quot;}
      }
}
How does Struts handle exceptions?
<global-results>
  <result name=quot;errorquot;/>
</global-results>

<global-exception-mappings>
 <exception-mapping
  exception=quot;java.lang.Exceptionquot; result=quot;errorquot;/>
</global-exception-mappings>
How does Struts handle exceptions?
<h2>An unexpected error has occurred</h2>
  <p>Please report this error to your system
administrator or appropriate technical support
personnel. Thank you for your cooperation.</p>
  <hr/>
  <h3>Error Message</h3>
    <p>
      <s:property value=quot;%{exception.message}quot;/>
    </p>
    <hr/>
    <h3>Technical Details</h3>
    <p>
      <s:property value=quot;%{exceptionStack}quot;/>
    </p>
How does Struts handle exceptions?
public String getExceptionMessage() {
 ActionContext context = ActionContext.getContext();
 Object value = context.getValueStack().
  findValue(quot;exception.messagequot;);
  if (value==null) return null;
  return value.toString();
}

public String getExceptionStack() {
 ActionContext context = ActionContext.getContext();
 Object value = context.getValueStack().
  findValue(quot;exceptionStackquot;);
 if (value==null) return null;
 return value.toString();
}
How does Struts handle exceptions?
public String execute() throws Exception {
  throw new Exception(quot;Whoops!quot;);
// return quot;successquot;;
}




  getExceptionMessage :” “Whoops!”
  getExceptionStack: “java.lang.exception
  Whoops! at actions.ContactLoadAction
  ...
How do widgets handle errors?
<!-- ... -->

</div>
<div id=quot;elErrorquot; class=quot;errorquot;></div>
<div

<!-- ... -->
How do widgets handle errors?
my.asyncRequestException = function (o) {
  alert(quot;Error Communicating with Server! See
message area for details.quot;);
  var sTemplate = quot;<table>
   <tr><th>Message:&nbsp;</th>
   <td>{exceptionMessage}</td></tr>
   <tr><th>Location:</th>
   <td>{exceptionStack}</td></tr>
  </table>quot;;
  var oPayload = eval(quot;(quot; + o + quot;)quot;) ;
  document.getElementById(quot;elErrorquot;).innerHTML =
    sTemplate.supplant(oPayload);
How do widgets handle errors?
What about error handling?
var onContentReady = function() {
 _Contact = new MY.Contact();
 my.oEvent.subscribe(quot;contactLoadquot;,_Contact.load,
   _Contact);
 // YAHOO.util.Connect.asyncRequest('POST', quot;contact-
   load.doquot;, callback, null);
 my.asyncRequest(quot;contact-load.doquot;,
   my.oEvent.onContactLoadReturn);
 };
my.asyncRequest = function (sAction, fnCallback) {
 return YAHOO.util.Connect.asyncRequest(quot;POSTquot;, sAction,
{
   success : function(o) {
    var oPayload = eval(quot;(quot; + o.responseText + quot;)quot;) ;
    fnCallback(oPayload);
  }
 });
};
my.asyncRequest = function (sAction, fnCallback) {
 return YAHOO.util.Connect.asyncRequest(quot;POSTquot;, sAction,
{
   success : function(o) {
    var oPayload = eval(quot;(quot; + o.responseText + quot;)quot;) ;
    if (oPayload.exceptionMessage) {
     my.asyncRequestException(oPayload);
    }
    fnCallback(oPayload);
  }
 });
};
my.asyncRequestException = function (oPayload) {
 my.errorMessage(oPayload.exceptionMessage,
  oPayload.exceptionStack);
};
my.errorMessage = function (sMessage, sStackTrace) {
  alert(quot;Error Communicating with Server! // ...
  var sTemplate = quot;<table><tr> // ...
  var oContext = {message: sMessage,
    stackTrace: sStackTrace};
  document.getElementById(quot;elErrorquot;).innerHTML =
    sTemplate.supplant(oContext);
  my.isMessage(true);
  my.error(oContext);
};
Is that all there is?
During this session, we covered
  Integrating an Ajax UI with Struts 2
  Using Yahoo User Interface (YUI) Library
  Using Struts to provide services to Ajax U
Struts University Series
Whats up with Planet Yazaar?
Development team Yahoo! Employees
  Something like Spring, Hibernate
  Unlike Apache projects
No formal mechanism for contributions
Whats up with Planet Yazaar?
Development team Yahoo! Employees
  Something like Spring, Hibernate
  Unlike Apache projects
No formal mechanism for contributions
A cathderal, rather than a bazaar
What's up with Planet Yazaar?
Yazaar - (Yahoo + Bazaar = Yazaar)
Accepts and maintains contributor
extensions and documentation
Working toward quot;soup to nutsquot; project
documentation
Public repository with version-to-version
change logs
What's up with Planet Yazaar?
 Just as an aside ...
  Yahoo GeoCities for public web site
  Uses GoogleCode for repository
  Google Group for mailing list and change
  logs
  Yahoo 360 for Blog
Square One University Series

Weitere ähnliche Inhalte

Was ist angesagt?

Advanced java practical semester 6_computer science
Advanced java practical semester 6_computer scienceAdvanced java practical semester 6_computer science
Advanced java practical semester 6_computer scienceNiraj Bharambe
 
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2KZepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2KThomas Fuchs
 
How to Add End-to-End Encryption to Your React App
How to Add End-to-End Encryption to Your React AppHow to Add End-to-End Encryption to Your React App
How to Add End-to-End Encryption to Your React AppIronCore Labs
 
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Domenic Denicola
 
async/await in Swift
async/await in Swiftasync/await in Swift
async/await in SwiftPeter Friese
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced JavascriptAdieu
 
JavaScript and the AST
JavaScript and the ASTJavaScript and the AST
JavaScript and the ASTJarrod Overson
 
Introduction into Struts2 jQuery Grid Tags
Introduction into Struts2 jQuery Grid TagsIntroduction into Struts2 jQuery Grid Tags
Introduction into Struts2 jQuery Grid TagsJohannes Geppert
 
.NET Database Toolkit
.NET Database Toolkit.NET Database Toolkit
.NET Database Toolkitwlscaudill
 
Understanding Asynchronous JavaScript
Understanding Asynchronous JavaScriptUnderstanding Asynchronous JavaScript
Understanding Asynchronous JavaScriptjnewmanux
 
Embedded Typesafe Domain Specific Languages for Java
Embedded Typesafe Domain Specific Languages for JavaEmbedded Typesafe Domain Specific Languages for Java
Embedded Typesafe Domain Specific Languages for JavaJevgeni Kabanov
 
Secret unit testing tools no one ever told you about
Secret unit testing tools no one ever told you aboutSecret unit testing tools no one ever told you about
Secret unit testing tools no one ever told you aboutDror Helper
 
Understanding Object Oriented Javascript - Coffee@DBG June
Understanding Object Oriented Javascript - Coffee@DBG JuneUnderstanding Object Oriented Javascript - Coffee@DBG June
Understanding Object Oriented Javascript - Coffee@DBG JuneDeepu S Nath
 
Making Java more dynamic: runtime code generation for the JVM
Making Java more dynamic: runtime code generation for the JVMMaking Java more dynamic: runtime code generation for the JVM
Making Java more dynamic: runtime code generation for the JVMRafael Winterhalter
 

Was ist angesagt? (20)

ORM Injection
ORM InjectionORM Injection
ORM Injection
 
Advanced java practical semester 6_computer science
Advanced java practical semester 6_computer scienceAdvanced java practical semester 6_computer science
Advanced java practical semester 6_computer science
 
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2KZepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
 
How to Add End-to-End Encryption to Your React App
How to Add End-to-End Encryption to Your React AppHow to Add End-to-End Encryption to Your React App
How to Add End-to-End Encryption to Your React App
 
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
 
async/await in Swift
async/await in Swiftasync/await in Swift
async/await in Swift
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced Javascript
 
JavaScript and the AST
JavaScript and the ASTJavaScript and the AST
JavaScript and the AST
 
ES2015 workflows
ES2015 workflowsES2015 workflows
ES2015 workflows
 
Introduction into Struts2 jQuery Grid Tags
Introduction into Struts2 jQuery Grid TagsIntroduction into Struts2 jQuery Grid Tags
Introduction into Struts2 jQuery Grid Tags
 
Java Script Best Practices
Java Script Best PracticesJava Script Best Practices
Java Script Best Practices
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScript
 
.NET Database Toolkit
.NET Database Toolkit.NET Database Toolkit
.NET Database Toolkit
 
Understanding Asynchronous JavaScript
Understanding Asynchronous JavaScriptUnderstanding Asynchronous JavaScript
Understanding Asynchronous JavaScript
 
Embedded Typesafe Domain Specific Languages for Java
Embedded Typesafe Domain Specific Languages for JavaEmbedded Typesafe Domain Specific Languages for Java
Embedded Typesafe Domain Specific Languages for Java
 
Secret unit testing tools no one ever told you about
Secret unit testing tools no one ever told you aboutSecret unit testing tools no one ever told you about
Secret unit testing tools no one ever told you about
 
JDK Power Tools
JDK Power ToolsJDK Power Tools
JDK Power Tools
 
Understanding Object Oriented Javascript - Coffee@DBG June
Understanding Object Oriented Javascript - Coffee@DBG JuneUnderstanding Object Oriented Javascript - Coffee@DBG June
Understanding Object Oriented Javascript - Coffee@DBG June
 
Making Java more dynamic: runtime code generation for the JVM
Making Java more dynamic: runtime code generation for the JVMMaking Java more dynamic: runtime code generation for the JVM
Making Java more dynamic: runtime code generation for the JVM
 
servlets
servletsservlets
servlets
 

Andere mochten auch

The secret life_of_open_source
The secret life_of_open_sourceThe secret life_of_open_source
The secret life_of_open_sourceTed Husted
 
Open Source Secret Sauce
Open Source Secret SauceOpen Source Secret Sauce
Open Source Secret SauceTed Husted
 
Agile Analysis with Use Cases: Balancing Utility with Simplicity
Agile Analysis with Use Cases: Balancing Utility with SimplicityAgile Analysis with Use Cases: Balancing Utility with Simplicity
Agile Analysis with Use Cases: Balancing Utility with SimplicityTed Husted
 
Open Source Secret Sauce - Lugor Sep 2011
Open Source Secret Sauce - Lugor Sep 2011Open Source Secret Sauce - Lugor Sep 2011
Open Source Secret Sauce - Lugor Sep 2011Ted Husted
 
Testing Ajax Applications
Testing Ajax ApplicationsTesting Ajax Applications
Testing Ajax ApplicationsTed Husted
 
Testing Ajax Web Applications
Testing Ajax Web ApplicationsTesting Ajax Web Applications
Testing Ajax Web ApplicationsTed Husted
 
.NET @ apache.org
 .NET @ apache.org .NET @ apache.org
.NET @ apache.orgTed Husted
 

Andere mochten auch (10)

The secret life_of_open_source
The secret life_of_open_sourceThe secret life_of_open_source
The secret life_of_open_source
 
Open Source Secret Sauce
Open Source Secret SauceOpen Source Secret Sauce
Open Source Secret Sauce
 
Agile Analysis with Use Cases: Balancing Utility with Simplicity
Agile Analysis with Use Cases: Balancing Utility with SimplicityAgile Analysis with Use Cases: Balancing Utility with Simplicity
Agile Analysis with Use Cases: Balancing Utility with Simplicity
 
Ship It!
Ship It!Ship It!
Ship It!
 
Open Source Secret Sauce - Lugor Sep 2011
Open Source Secret Sauce - Lugor Sep 2011Open Source Secret Sauce - Lugor Sep 2011
Open Source Secret Sauce - Lugor Sep 2011
 
Coding Ajax
Coding AjaxCoding Ajax
Coding Ajax
 
Testing Ajax Applications
Testing Ajax ApplicationsTesting Ajax Applications
Testing Ajax Applications
 
Testing Ajax Web Applications
Testing Ajax Web ApplicationsTesting Ajax Web Applications
Testing Ajax Web Applications
 
.NET @ apache.org
 .NET @ apache.org .NET @ apache.org
.NET @ apache.org
 
Testing Tools
Testing ToolsTesting Tools
Testing Tools
 

Ähnlich wie Ajax on Struts: Coding an Ajax Application with Struts 2

Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Guillaume Laforge
 
Event-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 EngineEvent-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 EngineRicardo Silva
 
Introduction To Groovy 2005
Introduction To Groovy 2005Introduction To Groovy 2005
Introduction To Groovy 2005Tugdual Grall
 
Migrating from Struts 1 to Struts 2
Migrating from Struts 1 to Struts 2Migrating from Struts 1 to Struts 2
Migrating from Struts 1 to Struts 2Matt Raible
 
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディングXitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディングscalaconfjp
 
Xitrum @ Scala Matsuri Tokyo 2014
Xitrum @ Scala Matsuri Tokyo 2014Xitrum @ Scala Matsuri Tokyo 2014
Xitrum @ Scala Matsuri Tokyo 2014Ngoc Dao
 
beyond tellerrand: Mobile Apps with JavaScript – There's More Than Web
beyond tellerrand: Mobile Apps with JavaScript – There's More Than Webbeyond tellerrand: Mobile Apps with JavaScript – There's More Than Web
beyond tellerrand: Mobile Apps with JavaScript – There's More Than WebHeiko Behrens
 
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)Carles Farré
 
Don't Be Afraid of Abstract Syntax Trees
Don't Be Afraid of Abstract Syntax TreesDon't Be Afraid of Abstract Syntax Trees
Don't Be Afraid of Abstract Syntax TreesJamund Ferguson
 
Java Intro
Java IntroJava Intro
Java Introbackdoor
 
CouchDB on Android
CouchDB on AndroidCouchDB on Android
CouchDB on AndroidSven Haiges
 
Pascarello_Investigating JavaScript and Ajax Security
Pascarello_Investigating JavaScript and Ajax SecurityPascarello_Investigating JavaScript and Ajax Security
Pascarello_Investigating JavaScript and Ajax Securityamiable_indian
 
Boston Computing Review - Java Server Pages
Boston Computing Review - Java Server PagesBoston Computing Review - Java Server Pages
Boston Computing Review - Java Server PagesJohn Brunswick
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing UpDavid Padbury
 

Ähnlich wie Ajax on Struts: Coding an Ajax Application with Struts 2 (20)

Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008
 
Event-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 EngineEvent-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 Engine
 
Go react codelab
Go react codelabGo react codelab
Go react codelab
 
Introduction To Groovy 2005
Introduction To Groovy 2005Introduction To Groovy 2005
Introduction To Groovy 2005
 
Migrating from Struts 1 to Struts 2
Migrating from Struts 1 to Struts 2Migrating from Struts 1 to Struts 2
Migrating from Struts 1 to Struts 2
 
A More Flash Like Web?
A More Flash Like Web?A More Flash Like Web?
A More Flash Like Web?
 
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディングXitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
 
Xitrum @ Scala Matsuri Tokyo 2014
Xitrum @ Scala Matsuri Tokyo 2014Xitrum @ Scala Matsuri Tokyo 2014
Xitrum @ Scala Matsuri Tokyo 2014
 
beyond tellerrand: Mobile Apps with JavaScript – There's More Than Web
beyond tellerrand: Mobile Apps with JavaScript – There's More Than Webbeyond tellerrand: Mobile Apps with JavaScript – There's More Than Web
beyond tellerrand: Mobile Apps with JavaScript – There's More Than Web
 
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
 
Don't Be Afraid of Abstract Syntax Trees
Don't Be Afraid of Abstract Syntax TreesDon't Be Afraid of Abstract Syntax Trees
Don't Be Afraid of Abstract Syntax Trees
 
Reversing JavaScript
Reversing JavaScriptReversing JavaScript
Reversing JavaScript
 
Java Intro
Java IntroJava Intro
Java Intro
 
CouchDB on Android
CouchDB on AndroidCouchDB on Android
CouchDB on Android
 
Pascarello_Investigating JavaScript and Ajax Security
Pascarello_Investigating JavaScript and Ajax SecurityPascarello_Investigating JavaScript and Ajax Security
Pascarello_Investigating JavaScript and Ajax Security
 
JS everywhere 2011
JS everywhere 2011JS everywhere 2011
JS everywhere 2011
 
I Feel Pretty
I Feel PrettyI Feel Pretty
I Feel Pretty
 
Boston Computing Review - Java Server Pages
Boston Computing Review - Java Server PagesBoston Computing Review - Java Server Pages
Boston Computing Review - Java Server Pages
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing Up
 
Android best practices
Android best practicesAndroid best practices
Android best practices
 

Mehr von Ted Husted

NU FaceBook 101 JCC 2010
NU  FaceBook 101 JCC 2010NU  FaceBook 101 JCC 2010
NU FaceBook 101 JCC 2010Ted Husted
 
Developing java Web Applications Using Google Apps RJUG 2011
Developing java Web Applications Using Google Apps RJUG 2011Developing java Web Applications Using Google Apps RJUG 2011
Developing java Web Applications Using Google Apps RJUG 2011Ted Husted
 
Open source secret_sauce_apache_con_2010
Open source secret_sauce_apache_con_2010Open source secret_sauce_apache_con_2010
Open source secret_sauce_apache_con_2010Ted Husted
 
Drupal kickstart-workshop
Drupal kickstart-workshopDrupal kickstart-workshop
Drupal kickstart-workshopTed Husted
 
Open source-secret-sauce-rit-2010
Open source-secret-sauce-rit-2010Open source-secret-sauce-rit-2010
Open source-secret-sauce-rit-2010Ted Husted
 
Testing Web Application Security
Testing Web Application SecurityTesting Web Application Security
Testing Web Application SecurityTed Husted
 
API Doc Smackdown
API Doc SmackdownAPI Doc Smackdown
API Doc SmackdownTed Husted
 
Testing The Testers
Testing The TestersTesting The Testers
Testing The TestersTed Husted
 

Mehr von Ted Husted (8)

NU FaceBook 101 JCC 2010
NU  FaceBook 101 JCC 2010NU  FaceBook 101 JCC 2010
NU FaceBook 101 JCC 2010
 
Developing java Web Applications Using Google Apps RJUG 2011
Developing java Web Applications Using Google Apps RJUG 2011Developing java Web Applications Using Google Apps RJUG 2011
Developing java Web Applications Using Google Apps RJUG 2011
 
Open source secret_sauce_apache_con_2010
Open source secret_sauce_apache_con_2010Open source secret_sauce_apache_con_2010
Open source secret_sauce_apache_con_2010
 
Drupal kickstart-workshop
Drupal kickstart-workshopDrupal kickstart-workshop
Drupal kickstart-workshop
 
Open source-secret-sauce-rit-2010
Open source-secret-sauce-rit-2010Open source-secret-sauce-rit-2010
Open source-secret-sauce-rit-2010
 
Testing Web Application Security
Testing Web Application SecurityTesting Web Application Security
Testing Web Application Security
 
API Doc Smackdown
API Doc SmackdownAPI Doc Smackdown
API Doc Smackdown
 
Testing The Testers
Testing The TestersTesting The Testers
Testing The Testers
 

Kürzlich hochgeladen

Implementing Exponential Accelerators.pptx
Implementing Exponential Accelerators.pptxImplementing Exponential Accelerators.pptx
Implementing Exponential Accelerators.pptxRich Reba
 
How do I Check My Health Issues in Astrology.pdf
How do I Check My Health Issues in Astrology.pdfHow do I Check My Health Issues in Astrology.pdf
How do I Check My Health Issues in Astrology.pdfshubhamaapkikismat
 
Psychic Reading | Spiritual Guidance – Astro Ganesh Ji
Psychic Reading | Spiritual Guidance – Astro Ganesh JiPsychic Reading | Spiritual Guidance – Astro Ganesh Ji
Psychic Reading | Spiritual Guidance – Astro Ganesh Jiastral oracle
 
Features of a Call Recorder Spy App for Android.pdf
Features of a Call Recorder Spy App for Android.pdfFeatures of a Call Recorder Spy App for Android.pdf
Features of a Call Recorder Spy App for Android.pdfOne Monitar
 
trending-flavors-and-ingredients-in-salty-snacks-us-2024_Redacted-V2.pdf
trending-flavors-and-ingredients-in-salty-snacks-us-2024_Redacted-V2.pdftrending-flavors-and-ingredients-in-salty-snacks-us-2024_Redacted-V2.pdf
trending-flavors-and-ingredients-in-salty-snacks-us-2024_Redacted-V2.pdfMintel Group
 
Send Files | Sendbig.comSend Files | Sendbig.com
Send Files | Sendbig.comSend Files | Sendbig.comSend Files | Sendbig.comSend Files | Sendbig.com
Send Files | Sendbig.comSend Files | Sendbig.comSendBig4
 
GUIDELINES ON USEFUL FORMS IN FREIGHT FORWARDING (F) Danny Diep Toh MBA.pdf
GUIDELINES ON USEFUL FORMS IN FREIGHT FORWARDING (F) Danny Diep Toh MBA.pdfGUIDELINES ON USEFUL FORMS IN FREIGHT FORWARDING (F) Danny Diep Toh MBA.pdf
GUIDELINES ON USEFUL FORMS IN FREIGHT FORWARDING (F) Danny Diep Toh MBA.pdfDanny Diep To
 
14680-51-4.pdf Good quality CAS Good quality CAS
14680-51-4.pdf  Good  quality CAS Good  quality CAS14680-51-4.pdf  Good  quality CAS Good  quality CAS
14680-51-4.pdf Good quality CAS Good quality CAScathy664059
 
Appkodes Tinder Clone Script with Customisable Solutions.pptx
Appkodes Tinder Clone Script with Customisable Solutions.pptxAppkodes Tinder Clone Script with Customisable Solutions.pptx
Appkodes Tinder Clone Script with Customisable Solutions.pptxappkodes
 
EUDR Info Meeting Ethiopian coffee exporters
EUDR Info Meeting Ethiopian coffee exportersEUDR Info Meeting Ethiopian coffee exporters
EUDR Info Meeting Ethiopian coffee exportersPeter Horsten
 
Pitch Deck Teardown: Xpanceo's $40M Seed deck
Pitch Deck Teardown: Xpanceo's $40M Seed deckPitch Deck Teardown: Xpanceo's $40M Seed deck
Pitch Deck Teardown: Xpanceo's $40M Seed deckHajeJanKamps
 
1911 Gold Corporate Presentation Apr 2024.pdf
1911 Gold Corporate Presentation Apr 2024.pdf1911 Gold Corporate Presentation Apr 2024.pdf
1911 Gold Corporate Presentation Apr 2024.pdfShaun Heinrichs
 
WSMM Media and Entertainment Feb_March_Final.pdf
WSMM Media and Entertainment Feb_March_Final.pdfWSMM Media and Entertainment Feb_March_Final.pdf
WSMM Media and Entertainment Feb_March_Final.pdfJamesConcepcion7
 
How Generative AI Is Transforming Your Business | Byond Growth Insights | Apr...
How Generative AI Is Transforming Your Business | Byond Growth Insights | Apr...How Generative AI Is Transforming Your Business | Byond Growth Insights | Apr...
How Generative AI Is Transforming Your Business | Byond Growth Insights | Apr...Hector Del Castillo, CPM, CPMM
 
20200128 Ethical by Design - Whitepaper.pdf
20200128 Ethical by Design - Whitepaper.pdf20200128 Ethical by Design - Whitepaper.pdf
20200128 Ethical by Design - Whitepaper.pdfChris Skinner
 
Welding Electrode Making Machine By Deccan Dynamics
Welding Electrode Making Machine By Deccan DynamicsWelding Electrode Making Machine By Deccan Dynamics
Welding Electrode Making Machine By Deccan DynamicsIndiaMART InterMESH Limited
 
1911 Gold Corporate Presentation Apr 2024.pdf
1911 Gold Corporate Presentation Apr 2024.pdf1911 Gold Corporate Presentation Apr 2024.pdf
1911 Gold Corporate Presentation Apr 2024.pdfShaun Heinrichs
 
Planetary and Vedic Yagyas Bring Positive Impacts in Life
Planetary and Vedic Yagyas Bring Positive Impacts in LifePlanetary and Vedic Yagyas Bring Positive Impacts in Life
Planetary and Vedic Yagyas Bring Positive Impacts in LifeBhavana Pujan Kendra
 
Cyber Security Training in Office Environment
Cyber Security Training in Office EnvironmentCyber Security Training in Office Environment
Cyber Security Training in Office Environmentelijahj01012
 

Kürzlich hochgeladen (20)

Implementing Exponential Accelerators.pptx
Implementing Exponential Accelerators.pptxImplementing Exponential Accelerators.pptx
Implementing Exponential Accelerators.pptx
 
How do I Check My Health Issues in Astrology.pdf
How do I Check My Health Issues in Astrology.pdfHow do I Check My Health Issues in Astrology.pdf
How do I Check My Health Issues in Astrology.pdf
 
Psychic Reading | Spiritual Guidance – Astro Ganesh Ji
Psychic Reading | Spiritual Guidance – Astro Ganesh JiPsychic Reading | Spiritual Guidance – Astro Ganesh Ji
Psychic Reading | Spiritual Guidance – Astro Ganesh Ji
 
Features of a Call Recorder Spy App for Android.pdf
Features of a Call Recorder Spy App for Android.pdfFeatures of a Call Recorder Spy App for Android.pdf
Features of a Call Recorder Spy App for Android.pdf
 
trending-flavors-and-ingredients-in-salty-snacks-us-2024_Redacted-V2.pdf
trending-flavors-and-ingredients-in-salty-snacks-us-2024_Redacted-V2.pdftrending-flavors-and-ingredients-in-salty-snacks-us-2024_Redacted-V2.pdf
trending-flavors-and-ingredients-in-salty-snacks-us-2024_Redacted-V2.pdf
 
Send Files | Sendbig.comSend Files | Sendbig.com
Send Files | Sendbig.comSend Files | Sendbig.comSend Files | Sendbig.comSend Files | Sendbig.com
Send Files | Sendbig.comSend Files | Sendbig.com
 
GUIDELINES ON USEFUL FORMS IN FREIGHT FORWARDING (F) Danny Diep Toh MBA.pdf
GUIDELINES ON USEFUL FORMS IN FREIGHT FORWARDING (F) Danny Diep Toh MBA.pdfGUIDELINES ON USEFUL FORMS IN FREIGHT FORWARDING (F) Danny Diep Toh MBA.pdf
GUIDELINES ON USEFUL FORMS IN FREIGHT FORWARDING (F) Danny Diep Toh MBA.pdf
 
14680-51-4.pdf Good quality CAS Good quality CAS
14680-51-4.pdf  Good  quality CAS Good  quality CAS14680-51-4.pdf  Good  quality CAS Good  quality CAS
14680-51-4.pdf Good quality CAS Good quality CAS
 
Appkodes Tinder Clone Script with Customisable Solutions.pptx
Appkodes Tinder Clone Script with Customisable Solutions.pptxAppkodes Tinder Clone Script with Customisable Solutions.pptx
Appkodes Tinder Clone Script with Customisable Solutions.pptx
 
EUDR Info Meeting Ethiopian coffee exporters
EUDR Info Meeting Ethiopian coffee exportersEUDR Info Meeting Ethiopian coffee exporters
EUDR Info Meeting Ethiopian coffee exporters
 
Pitch Deck Teardown: Xpanceo's $40M Seed deck
Pitch Deck Teardown: Xpanceo's $40M Seed deckPitch Deck Teardown: Xpanceo's $40M Seed deck
Pitch Deck Teardown: Xpanceo's $40M Seed deck
 
1911 Gold Corporate Presentation Apr 2024.pdf
1911 Gold Corporate Presentation Apr 2024.pdf1911 Gold Corporate Presentation Apr 2024.pdf
1911 Gold Corporate Presentation Apr 2024.pdf
 
WSMM Media and Entertainment Feb_March_Final.pdf
WSMM Media and Entertainment Feb_March_Final.pdfWSMM Media and Entertainment Feb_March_Final.pdf
WSMM Media and Entertainment Feb_March_Final.pdf
 
How Generative AI Is Transforming Your Business | Byond Growth Insights | Apr...
How Generative AI Is Transforming Your Business | Byond Growth Insights | Apr...How Generative AI Is Transforming Your Business | Byond Growth Insights | Apr...
How Generative AI Is Transforming Your Business | Byond Growth Insights | Apr...
 
20200128 Ethical by Design - Whitepaper.pdf
20200128 Ethical by Design - Whitepaper.pdf20200128 Ethical by Design - Whitepaper.pdf
20200128 Ethical by Design - Whitepaper.pdf
 
Welding Electrode Making Machine By Deccan Dynamics
Welding Electrode Making Machine By Deccan DynamicsWelding Electrode Making Machine By Deccan Dynamics
Welding Electrode Making Machine By Deccan Dynamics
 
1911 Gold Corporate Presentation Apr 2024.pdf
1911 Gold Corporate Presentation Apr 2024.pdf1911 Gold Corporate Presentation Apr 2024.pdf
1911 Gold Corporate Presentation Apr 2024.pdf
 
Planetary and Vedic Yagyas Bring Positive Impacts in Life
Planetary and Vedic Yagyas Bring Positive Impacts in LifePlanetary and Vedic Yagyas Bring Positive Impacts in Life
Planetary and Vedic Yagyas Bring Positive Impacts in Life
 
WAM Corporate Presentation April 12 2024.pdf
WAM Corporate Presentation April 12 2024.pdfWAM Corporate Presentation April 12 2024.pdf
WAM Corporate Presentation April 12 2024.pdf
 
Cyber Security Training in Office Environment
Cyber Security Training in Office EnvironmentCyber Security Training in Office Environment
Cyber Security Training in Office Environment
 

Ajax on Struts: Coding an Ajax Application with Struts 2

  • 1. Ajax on Struts: Coding an Ajax Application with Struts 2 Wednesday, October 1st, 2:35p-3:35p Ted Husted In this session, we explore How to integrate an Ajax UI framework with a Struts 2 business framework. Business services Struts can provide to an Ajax UI, Basics of the Struts 2 web application framework. Basics of the Yahoo User Interface Library (YUI).
  • 2. Ajax on Struts: Coding an Ajax Application with Struts 2 Square One University Series
  • 3. Ajax on Struts For the latest version of this presentation, visit http://slideshare.com/ted.husted For the latest version of source code, visit http://code.google.com/p/yazaar/
  • 4. Abstract Ajax is the web's hottest user interface. Struts is Java's most popular web framework. What happens when we put Ajax on Struts? During the session, we will cover Integrating an Ajax UI with Struts 2 Using Yahoo User Interface (YUI) Library Using Struts to provide services to Ajax UI
  • 5. Ajax on Struts What are Ajax widgets? What are we coding? Is there an Ajax architecture? How can we switch to server-side data? What about error-handling?
  • 6. Ajax on Struts What are Ajax widgets? What are we coding? Is there an Ajax architecture? How can we switch to server-side data? What about error-handling?
  • 7. What are Ajax widgets? Ajax lets scripts make requests and update content without a page refresh Widgets are “black-box” user interfrace (UI) components Typically, widgets are configured without touching the component's internals DataGrids, Calendars, Carousels, even TextBoxes
  • 8. What are Ajax widgets? Widgets can be used with any server platform PHP, Java, .NET, Ruby, Python Client-side widget provides UI Server-side technology provides data access and business logic
  • 9. What is Apache Struts? Free open-source framework for creating Java web applications Provides three major components Request handler Response handler Tag libraries for JSP, as well as Freemarker, and Velocity
  • 10. Can we use Ajax with a Struts application? XHR is just another request/response Struts can stream data as a response Use JSP scriptlets Use Ajax JSP tag libraries Use plain-vanilla Ajax libraries
  • 11. Why use Apache Struts? Mature, well-supported, well-understood Provides input validation and data conversion Interacts well with Spring, Hibernate, et al Defacto standard for Java web applications
  • 12. Where do we start? Case study Pure Ajax prototype Test data encapsulated as JSON Later, replace test data with JSON via XHR Use “spikes” to separates concerns
  • 13. How do we select an Ajax library? Submit before you commit Code your own sample application Pick the one that works for you and yours We tried Dojo and YUI
  • 16. Why Yahoo User Interface (YUI) Library? Well documented and supported Lots of working examples New BSD license Easy to read code Easy to hack code
  • 17. Ajax on Struts What are Ajax widgets? What are we coding? Is there an Ajax architecture? How can we switch to server-side daa? What about error-handling?
  • 18. What did we code? 1 Provide a list of employees. 2 Record employee's first name, last name, extension, username, hire date, and hours worked per week. 3 Allow list to be filtered by first name, last name, or username. 4 Allow full or filtered list to be sorted by any field. 5 Allow record to be updated by authorized users
  • 19. What did we code? Use YUI DataTable to display list Share DataTable record with data-entry form Use TabView to separate list and edit
  • 20.
  • 21.
  • 22. What are we going to code? Prototype with static data Request data from Struts 2 Action Use Struts 2 Plugin to return JSON
  • 23. How does the Struts 2 JSON plugin work? Exposes action properties as fields in a JSON record. { stringValue : quot;A string valuequot;, intArray: [10, 20], map: { Zaphod : quot;Just this guy, you knowquot;, Arthur : quot;Monkey-boyquot; }, record: quot;start a named recordquot; }
  • 24. public class ExampleOutputAction { private String stringValue = quot;A string valuequot;; public String getStringValue() { return stringValue; } public void setStringValue(String value) { stringValue = value; } private int[] intArray = {10, 20}; public int[] getIntArray() { return intArray; } public void setIntArray(int[] value) { intArray = value; } private Map map = new HashMap(); public Map getMap() { return map; } public void setMap(Map value) { map = value; }
  • 25. private String nextRecord = quot;start a named recordquot;; @JSON(name=quot;recordquot;) public String getNextRecord() { return nextRecord; } //'transient' fields are not serialized @SuppressWarnings(quot;unusedquot;) private transient String stayHome; //fields without getter method are not serialized @SuppressWarnings(quot;unusedquot;) private String noGetterForMe; public String execute() { map.put(quot;Zaphodquot;, quot;Just this guy, you knowquot;); map.put(quot;Arthurquot;, quot;Monkey-Boyquot;); return quot;successquot;; } }
  • 26.
  • 27. { quot;intArrayquot;:[10,20], quot;mapquot;: { quot;Arthurquot;: quot;Monkey-Boyquot;, quot;Zaphodquot;:quot;Just this guy, you knowquot;}, quot;recordquot;:quot;start a named recordquot;, quot;stringValuequot;:quot;A string valuequot; } { stringValue : quot;A string valuequot;, intArray: [10, 20], map: { Zaphod : quot;Just this guy, you knowquot;, Arthur : quot;Monkey-boyquot; }, record: quot;start a named recordquot; }
  • 28. package actions; import java.util.Map; import java.util.HashMap; import com.googlecode.jsonplugin.annotations.JSON; import org.texturemedia.smarturls.ParentPackage; import org.texturemedia.smarturls.Result; @ParentPackage(quot;json-defaultquot;) @Result(name=quot;successquot;, type=quot;jsonquot;, location=quot;quot;) public class ExampleOutputAction { private String stringValue = quot;A string valuequot;; // ...
  • 29. How did we code a UI using static data? Entry list Entry form List shares data with form
  • 30.
  • 31.
  • 32. Ajax on Struts What are Ajax widgets? What are we coding? Is there an Ajax architecture? How can we switch to server-side data? What about error-handling?
  • 33. Is there an Ajax architecture? <script src=quot;my.jsquot; type=quot;text/javascriptquot;> if (typeof parent.my != quot;undefinedquot;) { var my = parent.my; // application namespace } else { var my = {}; var my.oEvent = { // ... instantiate rest of my
  • 34. Is there an Ajax architecture? <script src=quot;contacts.jsquot; type=quot;text/javascriptquot;> </script> my.Contacts = function(){ my.Contacts.superclass.constructor.call(this); }; YAHOO.lang.extend(my.Contacts,YAHOO.yazaar.flev-base);
  • 35. What's a FLEV widget? Common business workflow is Find / List / Edit / View Or quot;FLEVquot; The FLEV widget defines one columnset and datasource to use with all four presentations
  • 36. MY.Contact.prototype.oColumnHeaders = [ {key:quot;first_namequot;, text:quot;First Namequot;, sortable:true, resizeable:true, editor:quot;textboxquot;, formClassName: quot;requiredquot;, formTitle: quot;Enter employee's first namequot;}, // more entries ]; key and text are shared attributes sortable, resizable are List attribute formClassName, formtitle are Edit attributes (validation)
  • 37. MY.Contact.prototype.oResponseSchema = { fields:[quot;idquot;, quot;last_namequot;, quot;first_namequot;, quot;extensionquot;, quot;usernamequot;, quot;hiredquot;, quot;hoursquot;, quot;editorquot;] }; MY.Contact.prototype.LOCAL_DATA = { result : [{id: 'c5b6bbb1-66d6-49cb-9db6- 743af6627828', last_name: 'Beeblebrox ', first_name: 'Zaphod ', extension: '555-123- 4565', username: 'zaphie ', hired: '04/01/1978', hours: -1, editor: '1'}, // ... ];
  • 38. my.oEvent.createEvent(quot;contactLoadquot;) my.oEvent.onContactLoadReturn = function(oData) { my.info(quot;Firing contactLoad Eventquot;); my.oEvent.fireEvent(quot;contactLoadquot;, oData); };
  • 39. <script type=quot;text/javascriptquot;> var onContentReady = function() { _Contact = new MY.Contact(); my.oEvent.subscribe(quot;contactLoadquot;,_Contact.load, _Contact); my.oEvent.onContactLoadReturn(_Contact.LOCAL_DATA); }; YAHOO.util.Event.onContentReady(quot;elBodyquot;, onContentReady); </script>
  • 40.
  • 41. Ajax on Struts What are Ajax widgets? What are we coding? Is there an Ajax architecture? How can we switch to server-side data? What about error-handling?
  • 42. How can we switch over to server-side data? Create an example Action that returns example data Create a database Action that returns persistent data
  • 43. public class ContactLoadAction { private List contactLoad = new ArrayList(); @JSON(name=quot;resultquot;) public List getContactLoad() { contactLoad.add(new Contact( quot;c5b6bbb1-66d6-49cb-9db6-743af6627828quot;, quot;Beeblebroxquot;, quot;Zaphodquot;, quot;555-123-4565quot;, quot;zaphiequot;, quot;04/01/1978quot;, quot;-1quot;, quot;1quot; )); // ... return contacts; }
  • 44. public class Contact { public Contact() {}; public Contact(String id, String last_name, String first_name, String extension, String username, String hired, String hours, String editor) { setId(id); setLast_name(last_name); setFirst_name(first_name); setExtension(extension); setUsername(username); setHired(new Date(hired)); setHours(new Double(hours)); setEditor(editor); } private String id; public void setId(String value) { id = value; } public String getId() { return id; } // more properties ...
  • 45.
  • 46. How can we switch over to server-side data? Action data: {quot;resultquot;:[{quot;editorquot;:quot;1quot;,quot;extensionquot;:quot;555-123- 4565quot;,quot;first_namequot;:quot;Zaphod quot;, ... ]} JavaScript data: my.Contact.prototype.LOCAL_DATA = {result:[{id: 'c5b6bbb1-66d6-49cb-9db6- 743af6627828', last_name: 'Beeblebrox ', first_name: 'Zaphod ' ...
  • 48. <script> var transaction = YAHOO.util.Connect.asyncRequest( 'POST', sUrl, callback, null); </script> var callback = { success: function(o) {/*success handler code*/}, failure: function(o) {/*failure handler code*/}, argument: [argument1, argument2, argument3] } var responseSuccess = function(o){ /* Please see the Success Case section for more * details on the response object's properties. * o.tId * o.status * o.statusText * o.getResponseHeader[ ] * o.getAllResponseHeaders * o.responseText * o.responseXML * o.argument */ };
  • 49. // my.oEvents.onContactLoadReturn(_Self.LOCAL_DATA); YAHOO.util.Connect.asyncRequest('POST', quot;contact- load.doquot;, callback, null); var callback = { success : function(o) { my.oEvent.onContactLoadReturn(o.responseText); } };
  • 50.
  • 51. {quot;resultquot;:[ {quot;editorquot;:quot;1quot;,quot;extensionquot;:quot;555-123- 4565quot;,quot;first_namequot;:quot;Zaphod quot;, ... ]} my.Contact.prototype.LOCAL_DATA = {result:[
  • 52. // my.oEvents.onContactLoadReturn(_Self.LOCAL_DATA); YAHOO.util.Connect.asyncRequest('GET', quot;contact-load.doquot;, callback, null); var callback = { success : function(o) { var payload = eval(quot;(quot; + o.responseText + quot;)quot;); my.oEvent.onContactLoadReturn(payload); } }; - var payload = eval(quot;(quot; + o.responseText + quot;)quot;) ; + var payload = jcontext.parseJSON(o.responseText); http://json.org/json.js
  • 53. What about JavaScript Hijacking? /* {quot;resultquot;:[{quot;editorquot;:quot;1quot;,quot;extensionquot;:quot;555-123-4565quot;, ... }]} */ var data = o.responseText; var payload = eval(quot;(quot;+data.substring(data.indexOf(quot;/*quot;)+2, data.lastIndexOf(quot;*/quot;))+quot;)quot;); my.oEvent.onContactLoadReturn(payload);
  • 54. What about JavaScript Hijacking? <package name=quot;my-defaultquot; extends=quot;json-defaultquot;> <result-types> <result-type name=quot;jsonquot; class=quot;com.googlecode.jsonplugin.JSONResultquot; default=quot;truequot;> <param name=quot;wrapWithCommentsquot;>true</param> </result-type> </result-types> <action name=quot;contact-loadquot; class=quot;actions.ContactLoadActionquot;> <result /> </action> </package>
  • 55.
  • 56. Ajax on Struts What are Ajax widgets? What are we coding? Is there an Ajax architecture? How can we switch to server-side data? What about error-handling?
  • 57. What about error handling? var callback = { success : function(o) { var payload = eval(quot;(quot; + o.responseText + quot;)quot;); my.oEvent.onContactLoadReturn(payload); } }; YAHOO.util.Connect.asyncRequest('POST', quot;contact- load.doquot;, callback, null);
  • 58. What about error handling? var callback = { success: function(o) {/*success handler code*/}, failure: function(o) {/*failure handler code*/}, argument: [argument1, argument2, argument3] }
  • 59. How does JSON-RPC handle errors? { quot;versionquot; : quot;1.1quot;, quot;errorquot; : { quot;namequot; : quot;JSONRPCErrorquot;, quot;codequot; : 123, quot;messagequot; : quot;An error occurred parsing the request object.quot;, quot;errorquot; : { quot;namequot; : quot;JSONErrorquot;, quot;messagequot; : quot;Bad arrayquot;, quot;atquot; : 42, quot;textquot; : quot;{quot;idquot;:1,quot;methodquot;:quot;sumquot;,quot;paramsquot;:[1,2,3,4,5}quot;} } }
  • 60. How does Struts handle exceptions? <global-results> <result name=quot;errorquot;/> </global-results> <global-exception-mappings> <exception-mapping exception=quot;java.lang.Exceptionquot; result=quot;errorquot;/> </global-exception-mappings>
  • 61. How does Struts handle exceptions? <h2>An unexpected error has occurred</h2> <p>Please report this error to your system administrator or appropriate technical support personnel. Thank you for your cooperation.</p> <hr/> <h3>Error Message</h3> <p> <s:property value=quot;%{exception.message}quot;/> </p> <hr/> <h3>Technical Details</h3> <p> <s:property value=quot;%{exceptionStack}quot;/> </p>
  • 62. How does Struts handle exceptions? public String getExceptionMessage() { ActionContext context = ActionContext.getContext(); Object value = context.getValueStack(). findValue(quot;exception.messagequot;); if (value==null) return null; return value.toString(); } public String getExceptionStack() { ActionContext context = ActionContext.getContext(); Object value = context.getValueStack(). findValue(quot;exceptionStackquot;); if (value==null) return null; return value.toString(); }
  • 63. How does Struts handle exceptions? public String execute() throws Exception { throw new Exception(quot;Whoops!quot;); // return quot;successquot;; } getExceptionMessage :” “Whoops!” getExceptionStack: “java.lang.exception Whoops! at actions.ContactLoadAction ...
  • 64. How do widgets handle errors? <!-- ... --> </div> <div id=quot;elErrorquot; class=quot;errorquot;></div> <div <!-- ... -->
  • 65. How do widgets handle errors? my.asyncRequestException = function (o) { alert(quot;Error Communicating with Server! See message area for details.quot;); var sTemplate = quot;<table> <tr><th>Message:&nbsp;</th> <td>{exceptionMessage}</td></tr> <tr><th>Location:</th> <td>{exceptionStack}</td></tr> </table>quot;; var oPayload = eval(quot;(quot; + o + quot;)quot;) ; document.getElementById(quot;elErrorquot;).innerHTML = sTemplate.supplant(oPayload);
  • 66. How do widgets handle errors?
  • 67. What about error handling? var onContentReady = function() { _Contact = new MY.Contact(); my.oEvent.subscribe(quot;contactLoadquot;,_Contact.load, _Contact); // YAHOO.util.Connect.asyncRequest('POST', quot;contact- load.doquot;, callback, null); my.asyncRequest(quot;contact-load.doquot;, my.oEvent.onContactLoadReturn); };
  • 68. my.asyncRequest = function (sAction, fnCallback) { return YAHOO.util.Connect.asyncRequest(quot;POSTquot;, sAction, { success : function(o) { var oPayload = eval(quot;(quot; + o.responseText + quot;)quot;) ; fnCallback(oPayload); } }); };
  • 69. my.asyncRequest = function (sAction, fnCallback) { return YAHOO.util.Connect.asyncRequest(quot;POSTquot;, sAction, { success : function(o) { var oPayload = eval(quot;(quot; + o.responseText + quot;)quot;) ; if (oPayload.exceptionMessage) { my.asyncRequestException(oPayload); } fnCallback(oPayload); } }); };
  • 70. my.asyncRequestException = function (oPayload) { my.errorMessage(oPayload.exceptionMessage, oPayload.exceptionStack); }; my.errorMessage = function (sMessage, sStackTrace) { alert(quot;Error Communicating with Server! // ... var sTemplate = quot;<table><tr> // ... var oContext = {message: sMessage, stackTrace: sStackTrace}; document.getElementById(quot;elErrorquot;).innerHTML = sTemplate.supplant(oContext); my.isMessage(true); my.error(oContext); };
  • 71.
  • 72.
  • 73. Is that all there is? During this session, we covered Integrating an Ajax UI with Struts 2 Using Yahoo User Interface (YUI) Library Using Struts to provide services to Ajax U
  • 75. Whats up with Planet Yazaar? Development team Yahoo! Employees Something like Spring, Hibernate Unlike Apache projects No formal mechanism for contributions
  • 76. Whats up with Planet Yazaar? Development team Yahoo! Employees Something like Spring, Hibernate Unlike Apache projects No formal mechanism for contributions A cathderal, rather than a bazaar
  • 77.
  • 78. What's up with Planet Yazaar? Yazaar - (Yahoo + Bazaar = Yazaar) Accepts and maintains contributor extensions and documentation Working toward quot;soup to nutsquot; project documentation Public repository with version-to-version change logs
  • 79.
  • 80. What's up with Planet Yazaar? Just as an aside ... Yahoo GeoCities for public web site Uses GoogleCode for repository Google Group for mailing list and change logs Yahoo 360 for Blog
  • 81.
  • 82.
  • 83.