<ul><li>In this session we explore: </li></ul><ul><ul><li>How to use the Java Web Parts taglib with Struts 1; </li></ul></...
Struts on Ajax:  Retrofitting Struts with Ajax Taglibs Square One University Series
<ul><li>For the latest version of this presentation,  visit  http://slideshare.com/ted.husted </li></ul><ul><li>For the la...
Abstract <ul><li>Struts is Java's most popular web framework. Ajax is the web's hottest user interface. What happens when ...
Retrofitting Struts <ul><li>Can we use Struts with Ajax? </li></ul><ul><li>Why choose AjaxParts Taglib? </li></ul><ul><li>...
Retrofitting Struts <ul><li>Can we use Struts with Ajax? </li></ul><ul><li>Why choose AjaxParts Taglib? </li></ul><ul><li>...
Retrofitting Struts <ul><li>Can we use Struts with Ajax? </li></ul><ul><li>Why choose AjaxParts taglib? </li></ul><ul><li>...
What is Ajax? <ul><li>Originally, acronym for &quot;Asynchronous JavaScript And XML.&quot;  </li></ul><ul><li>Technique, r...
What was life like before Ajax? <ul><li>&quot;web page as a flat document&quot; </li></ul><ul><li>To mimic GUI desktop app...
How does Ajax work? <ul><li>Ajax adds a &quot;background&quot; call to the server </li></ul><ul><ul><li>1 XMLHttpRequest r...
Can we use Ajax in a Struts app? <ul><li>XHR is just another request/response </li></ul><ul><li>Struts can stream data as ...
public   class  IndexResult  extends  Action { public  ActionForward execute( ActionMapping mapping, ActionForm form, Http...
public   class  IndexResult2  extends ActionSupport { private  InputStream  inputStream ; public  InputStream getInputStre...
What are some pure Ajax Libraries? <ul><li>Prototype  ( http://www.prototypejs.org/ ),  </li></ul><ul><li>JQuery  ( http:/...
http://www.prototypejs.org/
http://jquery.com/
What are some Ajax UI Libraries? <ul><li>Dojo  ( http://dojotoolkit.org/ ) </li></ul><ul><li>YUI  ( http://developer.yahoo...
<ul><ul><li>http://dojotoolkit.org/ </li></ul></ul>
<ul><ul><li>http://developer.yahoo.com/yui/ </li></ul></ul>
Are there Ajax JSP tag libraries? <ul><li>Ajax Tags  ( http://ajaxtags.sourceforge.net/ ) </li></ul><ul><li>ColdTags Suite...
<ul><ul><li>http://ajaxtags.sourceforge.net/ </li></ul></ul>
<ul><ul><li>http://servletsuite.blogspot.com/2006/06/coldtags-suite-ajax-edition.html </li></ul></ul>
<ul><ul><li>http://www.jenkov.com/prizetags/introduction.tmpl </li></ul></ul>
<ul><ul><li>http://json-taglib.sourceforge.net/ </li></ul></ul>
<ul><ul><li>http://javawebparts.sourceforge.net/ </li></ul></ul>
Retrofitting Struts <ul><li>Can we use Struts with Ajax? </li></ul><ul><li>Why choose AjaxParts Taglib (APT)? </li></ul><u...
Why choose AjaxParts Taglib? <ul><li>Designed for Java developers  </li></ul><ul><li>Requires no JavaScript knowledge  </l...
Why choose AjaxParts Taglib? <ul><li>Works with any Java web application </li></ul><ul><li>Handles sticky cross-browser is...
Retrofitting Struts <ul><li>Can we use Struts with Ajax? </li></ul><ul><li>Why choose AjaxParts taglib? </li></ul><ul><li>...
How about a Simple Hello World Example? <ul><li>1 Press a button  </li></ul><ul><li>2 Obtain a text message via Ajax </li>...
How about a Simple Hello World Example? <ul><li>1 Insert AjaxParts tags into our page </li></ul><ul><li>2 Add ajax-config....
< html > < head > < title > Simple Hello World Example </ title > </ head > < body > < input  id = &quot;hello-button&quot...
<%@  taglib  prefix = &quot;ajax&quot;  uri = &quot;javawebparts/ajaxparts/taglib&quot;  %> < html > < head > < title > Si...
ajax-config.xml < ajaxConfig > < group  ajaxRef = &quot;index&quot; > < element  ajaxRef = &quot;hello-button&quot; > < ev...
Hello World! I am an AJAX result from the (mock) server. index-result.txt
<web-app> <context-param> <param-name> AjaxPartsTaglibConfig </param-name> <param-value> /WEB-INF/ajax-config.xml </param-...
What JARS do we need? <ul><li>javawebparts-ajaxparts.jar </li></ul><ul><li>javawebparts-core.jar  </li></ul><ul><li>common...
 
 
Can we use a Struts action instead? <ul><li>Replace text file with action that returns text.  </li></ul>
public   class  IndexResult  extends  Action { public  ActionForward execute( ActionMapping mapping, ActionForm form, Http...
< action path = &quot;/index-result&quot; type = &quot;actions.IndexResult&quot; validate = &quot;false&quot;  /> struts-c...
<requestHandler type=&quot;std:SimpleRequest&quot; target=&quot;index-result.txt&quot;>   < requestHandler  type = &quot;s...
 
How about Struts 2? <ul><li>Copy and modify Action </li></ul><ul><li>Add action mapping </li></ul><ul><li>Change URI refer...
public   class  IndexResult2  extends ActionSupport { private  InputStream  inputStream ; public  InputStream getInputStre...
< package  name = &quot;ajaxwebparts&quot;  extends = &quot;struts-default&quot; > < action  name = &quot;index-result&quo...
<requestHandler type=&quot;std:SimpleRequest&quot; target=&quot;/index-result.do&quot;>   < requestHandler  type = &quot;s...
 
Is it really that easy? <ul><li>No Client Side coding required  </li></ul><ul><li>Setting text to <div> tag </li></ul><ul>...
Retrofitting Struts <ul><li>Can we use Struts with Ajax? </li></ul><ul><li>Why choose AjaxParts taglib? </li></ul><ul><li>...
How does AjaxParts work? <ul><li>Bind to a JavaScript event  </li></ul><ul><ul><li>RequestHandler </li></ul></ul><ul><ul><...
< ajaxConfig > < group  ajaxRef = &quot; index &quot; > < element  ajaxRef = &quot; hello-button &quot; > < event  type = ...
< responseHandler  type = &quot;std:InnerHTML&quot; > < parameter > hello-div </ parameter > </ responseHandler > < br  />...
What does <ajax:event> do? <ul><li>Attaches an JavaScript event to a HTML element </li></ul>
What does <ajax:event> do? < input  id = &quot;helloButton&quot;  type = &quot;button&quot;  value = &quot;Say Hello World...
What does <ajax:enable> do? <ul><li>Renders JavaScript for other tags on page  </li></ul><ul><li>Must appear after all oth...
What requestHandlers are there? <ul><li>SimpleRequest </li></ul><ul><ul><li>Sends request to target URI </li></ul></ul><ul...
What requestHandlers are there? <ul><li>SendByID </li></ul><ul><ul><li>submits a GET or POST for a list of elements, optio...
What responseHandlers are there? <ul><li>InnerHTML </li></ul><ul><ul><li>Sets response content to element's innerHTML </li...
What responseHandlers are there? <ul><li>Redirector </li></ul><ul><ul><li>Uses response content as a URI for a redirect; a...
What responseHandlers are there? <ul><li>TextBoxArea </li></ul><ul><ul><li>Populates text control from response </li></ul>...
What responseHandlers are there? <ul><li>FormManipulator  - Populates fields in a form from response content </li></ul><ul...
Is that all there is to AjaxParts? <ul><li>Powerful but easy to use </li></ul><ul><li>Built on a declarative foundation  <...
Is that all there is to AjaxParts? <ul><li>The AjaxParts Taglib from Java Web Parts: Ajax for Java Developers the Easy (ye...
Is that all there is to AjaxParts? <ul><li>Practical Ajax Projects With Java Technologies </li></ul><ul><ul><li>(Frank W. ...
Other Struts 1 Ajax Resources <ul><li>Sprinkle Some Ajax Magic in Your Struts Web Application </li></ul><ul><ul><li>(Paul ...
Retrofitting Struts <ul><li>Can we use Struts with Ajax? </li></ul><ul><li>Why choose AjaxParts taglib? </li></ul><ul><li>...
Are there new alternatives for Struts 2? <ul><li>Struts 2.0 Ajax Tag Themes </li></ul><ul><li>Struts 2.1 Ajax Tag Plugins ...
How do the S2 Ajax Tags work?  <ul><li>The Dojo plugin provides several tags </li></ul><ul><ul><li>a / link - make a remot...
How do the S2 Ajax Tags work?  <ul><li>The YUI plugin provides three tags </li></ul><ul><ul><li>autocompleter </li></ul></...
How do the S2 Ajax Tags work?  <ul><li>The YUI plugin provides three tags </li></ul><ul><ul><li>autocompleter </li></ul></...
 
 
 
<%@  taglib  prefix = &quot;yui&quot;  uri = &quot;/struts-yui-tags&quot;  %> <%@  taglib  prefix = &quot;s&quot;  uri = &...
< action  name = &quot;datepicker&quot;  class = &quot;actions.Datepicker&quot; > < result > datepicker.jsp </ result > </...
public   class  Datepicker  extends  ActionSupport { private  Date  datepicker ; public  Date getDatepicker() { return   d...
 
Are there other Struts 2  Ajax resources?  <ul><li>Turbocharge Your Pages with Ajax, Dojo, and Struts </li></ul><ul><ul><l...
Is that all there is? <ul><li>In this session, we covered </li></ul><ul><ul><li>Integrating Ajax with Struts 1 or Struts 2...
JSON-P support in APT <ul><li>Simply add jsonp=“true” to any <requestHandler> in ajax-config.xml </li></ul><ul><li>All sta...
Struts University Series
Upcoming SlideShare
Loading in...5
×

Retrofitting

3,135

Published on

Lets stir some Ajax wizardry into a conventional Struts application, without all the sweat and bother of writing our own JavaScript. Struts 1 and Struts 2 both support Ajax taglibs that look and feel just like ordinary JSP tags. If it's just a little bit of Ajax that you want, these tags will get you around the learning curve in record time.

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
3,135
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
50
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Retrofitting

  1. 1. <ul><li>In this session we explore: </li></ul><ul><ul><li>How to use the Java Web Parts taglib with Struts 1; </li></ul></ul><ul><ul><li>How to use the Ajax YUI plugin with Struts 2; </li></ul></ul><ul><ul><li>How to integrate Ajax features with Struts 1 or 2; </li></ul></ul><ul><ul><li>Basics of the AjaxParts Taglib; </li></ul></ul><ul><ul><li>Basics of the Struts 2 YUI plugin. </li></ul></ul>Struts on Ajax: Retrofitting Struts with Ajax Taglibs Tuesday, September 30th, 9a-10a Ted Husted
  2. 2. Struts on Ajax: Retrofitting Struts with Ajax Taglibs Square One University Series
  3. 3. <ul><li>For the latest version of this presentation, visit http://slideshare.com/ted.husted </li></ul><ul><li>For the latest version of source code, visit http://code.google.com/p/sq1-struts2 </li></ul>Struts on Ajax
  4. 4. Abstract <ul><li>Struts is Java's most popular web framework. Ajax is the web's hottest user interface. What happens when we put Struts on Ajax? </li></ul><ul><li>During the session, we will cover </li></ul><ul><ul><li>Integrating Ajax with Struts 1 or Struts 2 </li></ul></ul><ul><ul><li>Using the AjaxParts Taglib with Struts 1 or 2 </li></ul></ul><ul><ul><li>Using the Ajax YUI plugin with Struts 2 </li></ul></ul>
  5. 5. Retrofitting Struts <ul><li>Can we use Struts with Ajax? </li></ul><ul><li>Why choose AjaxParts Taglib? </li></ul><ul><li>How about a simple Hello World example? </li></ul><ul><li>How does AjaxParts Taglib actually work? </li></ul><ul><li>Are there new alternatives for Struts 2? </li></ul>
  6. 6. Retrofitting Struts <ul><li>Can we use Struts with Ajax? </li></ul><ul><li>Why choose AjaxParts Taglib? </li></ul><ul><li>How about a simple Hello World example? </li></ul><ul><li>How does AjaxParts Taglib actually work? </li></ul><ul><li>Are there new alternatives for Struts 2? </li></ul><ul><li>Special guest demonstration </li></ul>
  7. 7. Retrofitting Struts <ul><li>Can we use Struts with Ajax? </li></ul><ul><li>Why choose AjaxParts taglib? </li></ul><ul><li>How about a simple Hello World example? </li></ul><ul><li>How does AjaxParts actually work? </li></ul><ul><li>Are there new alternatives for Struts 2? </li></ul>
  8. 8. What is Ajax? <ul><li>Originally, acronym for &quot;Asynchronous JavaScript And XML.&quot; </li></ul><ul><li>Technique, rather than a framework (such as Struts). </li></ul><ul><li>Allows web pages to work like GUI apps </li></ul><ul><li>Already used by Microsoft and Google, among many, many others. </li></ul>
  9. 9. What was life like before Ajax? <ul><li>&quot;web page as a flat document&quot; </li></ul><ul><li>To mimic GUI desktop apps </li></ul><ul><ul><li>1 send all data with (a lot of) JavaScript </li></ul></ul><ul><ul><li>2 constant form submits back to the server </li></ul></ul><ul><li>Ajax gives you the best of both worlds: </li></ul><ul><ul><li>dynamic web pages on the client </li></ul></ul><ul><ul><li>server-side Java application </li></ul></ul>
  10. 10. How does Ajax work? <ul><li>Ajax adds a &quot;background&quot; call to the server </li></ul><ul><ul><li>1 XMLHttpRequest requests content asynchronously. </li></ul></ul><ul><ul><li>2 Content can be anything; JavaScript updates page. </li></ul></ul><ul><ul><li>3 Triggered by JavaScript events: onclick, onchange, onblur, ... </li></ul></ul>
  11. 11. Can we use Ajax in a Struts app? <ul><li>XHR is just another request/response </li></ul><ul><li>Struts can stream data as a response </li></ul><ul><li>Use pure Ajax libraries (with scriptlets) </li></ul><ul><li>Use Ajax widget libraries </li></ul><ul><li>Use Ajax JSP tag libraries </li></ul>
  12. 12. public class IndexResult extends Action { public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { response.setContentType( &quot;text/html&quot; ); PrintWriter out = response.getWriter(); out.println( &quot;Hello World! “ + “ This is an AJAX response “ + “ from a Struts Action.&quot; ); out.flush(); return null ; } } actions.IndexResult.java
  13. 13. public class IndexResult2 extends ActionSupport { private InputStream inputStream ; public InputStream getInputStream() { return inputStream ; } public String execute() throws Exception { inputStream = new StringBufferInputStream( &quot;Hello World! This is an AJAX response &quot; + &quot;from a Struts 2 Action.&quot; ); return SUCCESS ; } } actions.IndexResult2.java
  14. 14. What are some pure Ajax Libraries? <ul><li>Prototype ( http://www.prototypejs.org/ ), </li></ul><ul><li>JQuery ( http://jquery.com/ ) </li></ul>
  15. 15. http://www.prototypejs.org/
  16. 16. http://jquery.com/
  17. 17. What are some Ajax UI Libraries? <ul><li>Dojo ( http://dojotoolkit.org/ ) </li></ul><ul><li>YUI ( http://developer.yahoo.com/yui/ ) </li></ul>
  18. 18. <ul><ul><li>http://dojotoolkit.org/ </li></ul></ul>
  19. 19. <ul><ul><li>http://developer.yahoo.com/yui/ </li></ul></ul>
  20. 20. Are there Ajax JSP tag libraries? <ul><li>Ajax Tags ( http://ajaxtags.sourceforge.net/ ) </li></ul><ul><li>ColdTags Suite ( http://servletsuite.blogspot.com/2006/06/coldtags-suite-ajax-edition.html ) </li></ul><ul><li>Prize Tags ( http://www.jenkov.com/prizetags/introduction.tmpl ) </li></ul><ul><li>JSON-taglib ( http://json-taglib.sourceforge.net/ ) </li></ul><ul><li>AjaxParts Taglib ( http://javawebparts.sourceforge.net/ ) </li></ul>
  21. 21. <ul><ul><li>http://ajaxtags.sourceforge.net/ </li></ul></ul>
  22. 22. <ul><ul><li>http://servletsuite.blogspot.com/2006/06/coldtags-suite-ajax-edition.html </li></ul></ul>
  23. 23. <ul><ul><li>http://www.jenkov.com/prizetags/introduction.tmpl </li></ul></ul>
  24. 24. <ul><ul><li>http://json-taglib.sourceforge.net/ </li></ul></ul>
  25. 25. <ul><ul><li>http://javawebparts.sourceforge.net/ </li></ul></ul>
  26. 26. Retrofitting Struts <ul><li>Can we use Struts with Ajax? </li></ul><ul><li>Why choose AjaxParts Taglib (APT)? </li></ul><ul><li>How about a simple Hello World example? </li></ul><ul><li>How does AjaxParts actually work? </li></ul><ul><li>Are there new alternatives for Struts 2? </li></ul>
  27. 27. Why choose AjaxParts Taglib? <ul><li>Designed for Java developers </li></ul><ul><li>Requires no JavaScript knowledge </li></ul><ul><li>Declarative, event-driven approach </li></ul><ul><li>Uses only four tags (in combination) </li></ul>
  28. 28. Why choose AjaxParts Taglib? <ul><li>Works with any Java web application </li></ul><ul><li>Handles sticky cross-browser issues </li></ul><ul><li>Part of Java Web Parts (JWP) component library </li></ul><ul><li>Pure Ajax focus </li></ul><ul><ul><li>Like Prototype or JQuery </li></ul></ul><ul><li>Built-in JSON-P support </li></ul>
  29. 29. Retrofitting Struts <ul><li>Can we use Struts with Ajax? </li></ul><ul><li>Why choose AjaxParts taglib? </li></ul><ul><li>How about a simple Hello World example? </li></ul><ul><li>How does AjaxParts actually work? </li></ul><ul><li>Are there new alternatives for Struts 2? </li></ul>
  30. 30. How about a Simple Hello World Example? <ul><li>1 Press a button </li></ul><ul><li>2 Obtain a text message via Ajax </li></ul><ul><li>3 Write text message to screen </li></ul><ul><ul><li>without refresh </li></ul></ul><ul><li>[Say Hello World via Ajax] </li></ul><ul><ul><li>Hello World! </li></ul></ul>
  31. 31. How about a Simple Hello World Example? <ul><li>1 Insert AjaxParts tags into our page </li></ul><ul><li>2 Add ajax-config.xml file </li></ul><ul><li>3 Update web.xml </li></ul><ul><li>4 Drop in the JARs </li></ul><ul><li>Step 3 and 4 – Once per application. </li></ul>
  32. 32. < html > < head > < title > Simple Hello World Example </ title > </ head > < body > < input id = &quot;hello-button&quot; type = &quot;button&quot; value = &quot;Say Hello World via AJAX&quot; /> < br />< br /> < div id = &quot;hello-div&quot; ></ div > </ body > </ html > index.jsp
  33. 33. <%@ taglib prefix = &quot;ajax&quot; uri = &quot;javawebparts/ajaxparts/taglib&quot; %> < html > < head > < title > Simple Hello World Example </ title > </ head > < body > < input id = &quot;hello-button&quot; type = &quot;button&quot; value = &quot;Say Hello World via AJAX&quot; /> < ajax:event attachTo = &quot;hello-button&quot; ajaxRef = &quot;index/hello-button&quot; /> < br />< br /> < div id = &quot;hello-div&quot; ></ div > < ajax:enable /> </ body > </ html > index.jsp
  34. 34. ajax-config.xml < ajaxConfig > < group ajaxRef = &quot;index&quot; > < element ajaxRef = &quot;hello-button&quot; > < event type = &quot;onclick&quot; > < requestHandler type = &quot;std:SimpleRequest&quot; target = &quot; index-result.txt &quot; > < parameter /> </ requestHandler > < responseHandler type = &quot;std:InnerHTML&quot; > < parameter > hello-div </ parameter > </ responseHandler > </ event > </ element > </ group > </ ajaxConfig >
  35. 35. Hello World! I am an AJAX result from the (mock) server. index-result.txt
  36. 36. <web-app> <context-param> <param-name> AjaxPartsTaglibConfig </param-name> <param-value> /WEB-INF/ajax-config.xml </param-value> </context-param> <context-param> <param-name> AjaxPartsTaglibValidateConfig </param-name> <param-value> false </param-value> </context-param> web.xml
  37. 37. What JARS do we need? <ul><li>javawebparts-ajaxparts.jar </li></ul><ul><li>javawebparts-core.jar </li></ul><ul><li>commons-logging.jar </li></ul>
  38. 40. Can we use a Struts action instead? <ul><li>Replace text file with action that returns text. </li></ul>
  39. 41. public class IndexResult extends Action { public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { response.setContentType( &quot;text/html&quot; ); PrintWriter out = response.getWriter(); out.println( &quot;Hello World! “ + “ This is an AJAX response “ + “ from a Struts Action.&quot; ); out.flush(); return null ; } } actions.IndexResult.java
  40. 42. < action path = &quot;/index-result&quot; type = &quot;actions.IndexResult&quot; validate = &quot;false&quot; /> struts-config.xml
  41. 43. <requestHandler type=&quot;std:SimpleRequest&quot; target=&quot;index-result.txt&quot;> < requestHandler type = &quot;std:SimpleRequest&quot; target = &quot;/index-result.do&quot; > ajax-config.xml
  42. 45. How about Struts 2? <ul><li>Copy and modify Action </li></ul><ul><li>Add action mapping </li></ul><ul><li>Change URI reference </li></ul>
  43. 46. public class IndexResult2 extends ActionSupport { private InputStream inputStream ; public InputStream getInputStream() { return inputStream ; } public String execute() throws Exception { inputStream = new StringBufferInputStream( &quot;Hello World! This is an AJAX response &quot; + &quot;from a Struts 2 Action.&quot; ); return SUCCESS ; } } actions.IndexResult2.java
  44. 47. < package name = &quot;ajaxwebparts&quot; extends = &quot;struts-default&quot; > < action name = &quot;index-result&quot; class = &quot;actions.IndexResult2&quot; > < result type = &quot;stream&quot; > < param name = &quot;contentType&quot; > text/html </ param > < param name = &quot;inputName&quot; > inputStream </ param > </ result > </ action > </ package > struts.xml
  45. 48. <requestHandler type=&quot;std:SimpleRequest&quot; target=&quot;/index-result.do&quot;> < requestHandler type = &quot;std:SimpleRequest&quot; target = &quot;/index-result.action&quot; > ajax-config.xml
  46. 50. Is it really that easy? <ul><li>No Client Side coding required </li></ul><ul><li>Setting text to <div> tag </li></ul><ul><li>JavaWebParts Cookbook </li></ul><ul><ul><li>dynamically adding lines to a form </li></ul></ul><ul><ul><li>creating &quot;suggest&quot; textboxes </li></ul></ul><ul><ul><li>dynamic double select controls </li></ul></ul><ul><ul><li>and more ... </li></ul></ul>
  47. 51. Retrofitting Struts <ul><li>Can we use Struts with Ajax? </li></ul><ul><li>Why choose AjaxParts taglib? </li></ul><ul><li>How about a simple Hello World example? </li></ul><ul><li>How does AjaxParts actually work? </li></ul><ul><li>Are there new alternatives for Struts 2? </li></ul>
  48. 52. How does AjaxParts work? <ul><li>Bind to a JavaScript event </li></ul><ul><ul><li>RequestHandler </li></ul></ul><ul><ul><li>One or more ResponseHandlers </li></ul></ul>
  49. 53. < ajaxConfig > < group ajaxRef = &quot; index &quot; > < element ajaxRef = &quot; hello-button &quot; > < event type = &quot;onclick&quot; > < requestHandler type = &quot;std:SimpleRequest&quot; target = &quot; index-result.action &quot; > < parameter /> How does AjaxParts work? <body> < input id = &quot;hello-button&quot; type = &quot;button&quot; value = &quot;Say Hello World via AJAX&quot; /> < ajax:event attachTo = &quot;hello-button“ ajaxRef = &quot; index/hello-button &quot; />
  50. 54. < responseHandler type = &quot;std:InnerHTML&quot; > < parameter > hello-div </ parameter > </ responseHandler > < br />< br /> < div id = &quot; hello-div &quot; ></ div > </ body > < ajax:enable /> How does AjaxParts work?
  51. 55. What does <ajax:event> do? <ul><li>Attaches an JavaScript event to a HTML element </li></ul>
  52. 56. What does <ajax:event> do? < input id = &quot;helloButton&quot; type = &quot;button&quot; value = &quot;Say Hello World via AJAX&quot; /> < ajax:event attachTo = &quot;helloButton&quot; ajaxRef = &quot;index/hello-button&quot; /> <ul><li>Attaches (binds) a JavaScript event to a HTML element </li></ul>
  53. 57. What does <ajax:enable> do? <ul><li>Renders JavaScript for other tags on page </li></ul><ul><li>Must appear after all other APT tags </li></ul><ul><li>Usually after closing </body> tag </li></ul>
  54. 58. What requestHandlers are there? <ul><li>SimpleRequest </li></ul><ul><ul><li>Sends request to target URI </li></ul></ul><ul><li>SimpleXML </li></ul><ul><ul><li>Submits a form as a XML document </li></ul></ul><ul><li>QueryString </li></ul><ul><ul><li>Submits a form as a GET request </li></ul></ul><ul><li>Poster </li></ul><ul><ul><li>Submits a form as a POST request </li></ul></ul>
  55. 59. What requestHandlers are there? <ul><li>SendByID </li></ul><ul><ul><li>submits a GET or POST for a list of elements, optionally in XML </li></ul></ul><ul><li>(Your RequestHandler here) </li></ul><ul><ul><li>If you know a little JavaScript, you can write your own! </li></ul></ul>
  56. 60. What responseHandlers are there? <ul><li>InnerHTML </li></ul><ul><ul><li>Sets response content to element's innerHTML </li></ul></ul><ul><li>Alterer </li></ul><ul><ul><li>Raises a JavaScript alert() with the response content </li></ul></ul><ul><li>CodeExecuter </li></ul><ul><ul><li>Evaluates the response content as a script </li></ul></ul>
  57. 61. What responseHandlers are there? <ul><li>Redirector </li></ul><ul><ul><li>Uses response content as a URI for a redirect; alternatively, URI may be specified in configuration </li></ul></ul><ul><li>WindowOpener </li></ul><ul><ul><li>Opens a new window and populates it with response content </li></ul></ul>
  58. 62. What responseHandlers are there? <ul><li>TextBoxArea </li></ul><ul><ul><li>Populates text control from response </li></ul></ul><ul><li>SelectBox </li></ul><ul><ul><li>Populates <select> control from response </li></ul></ul><ul><ul><li><list> <option value=&quot;DD&quot;>EE</option> </list> </li></ul></ul>
  59. 63. What responseHandlers are there? <ul><li>FormManipulator - Populates fields in a form from response content </li></ul><ul><ul><li><form name=&quot;AA&quot;> <formproperty name=&quot;BB&quot; value=&quot;CC&quot;/> <element name=&quot;DD&quot; value=&quot;EE&quot;> <property name=&quot;FF&quot; value=&quot;GG&quot;/> </element> </form> </li></ul></ul>
  60. 64. Is that all there is to AjaxParts? <ul><li>Powerful but easy to use </li></ul><ul><li>Built on a declarative foundation </li></ul><ul><li>Utilizes event-driven paradigm </li></ul><ul><li>Works with Struts and other web application frameworks </li></ul><ul><li>Doesn't require in-depth JavaScript knowledge </li></ul>
  61. 65. Is that all there is to AjaxParts? <ul><li>The AjaxParts Taglib from Java Web Parts: Ajax for Java Developers the Easy (yet powerful) Way </li></ul><ul><ul><li>(Frank W Zammetti, http://www.omnytex.com/articles/apt/ ) </li></ul></ul><ul><li>JavaWebParts web site </li></ul><ul><ul><li>JWP Sample Application and JWP Cookbook </li></ul></ul><ul><ul><li>( http://javawebparts.sourceforge.net/ ) </li></ul></ul>
  62. 66. Is that all there is to AjaxParts? <ul><li>Practical Ajax Projects With Java Technologies </li></ul><ul><ul><li>(Frank W. Zammetti, ISBN 1-59059-695-1) </li></ul></ul><ul><li>Struts-Ajax-Crud or &quot;Select alters other select list&quot; </li></ul><ul><ul><li>(Rick Reumann, http://www.learntechnology.net/content/ajax/ajax_select_alter.jsp ) </li></ul></ul>
  63. 67. Other Struts 1 Ajax Resources <ul><li>Sprinkle Some Ajax Magic in Your Struts Web Application </li></ul><ul><ul><li>(Paul Browne, http://today.java.net/lpt/a/236 ) </li></ul></ul><ul><li>Ajax using XMLHttpRequest and Struts </li></ul><ul><ul><li>(Frank W. Zammetti, http://www.omnytex.com/articles/xhrstruts/ ) </li></ul></ul>
  64. 68. Retrofitting Struts <ul><li>Can we use Struts with Ajax? </li></ul><ul><li>Why choose AjaxParts taglib? </li></ul><ul><li>How about a simple Hello World example? </li></ul><ul><li>How does AjaxParts actually work? </li></ul><ul><li>Are there new alternatives for Struts 2? </li></ul>
  65. 69. Are there new alternatives for Struts 2? <ul><li>Struts 2.0 Ajax Tag Themes </li></ul><ul><li>Struts 2.1 Ajax Tag Plugins </li></ul><ul><ul><li>Dojo and (some) YUI </li></ul></ul><ul><li>GWT Plugin </li></ul><ul><ul><li>Uses Action as backend data source </li></ul></ul><ul><li>JSON Plugin </li></ul><ul><ul><li>Renders Action properties as JSON object </li></ul></ul>
  66. 70. How do the S2 Ajax Tags work? <ul><li>The Dojo plugin provides several tags </li></ul><ul><ul><li>a / link - make a remote call to the server using Ajax </li></ul></ul><ul><ul><li>form - Ajax-based validation via DWR </li></ul></ul><ul><ul><li>submit - Used with form tag </li></ul></ul><ul><ul><li>div - Obtain content for a div via remote call </li></ul></ul><ul><ul><li>tabbedpanel - content for each panel is object via remote call </li></ul></ul>
  67. 71. How do the S2 Ajax Tags work? <ul><li>The YUI plugin provides three tags </li></ul><ul><ul><li>autocompleter </li></ul></ul><ul><ul><li>datepicker </li></ul></ul><ul><ul><li>languages </li></ul></ul>
  68. 72. How do the S2 Ajax Tags work? <ul><li>The YUI plugin provides three tags </li></ul><ul><ul><li>autocompleter </li></ul></ul><ul><ul><li>datepicker </li></ul></ul><ul><ul><li>languages </li></ul></ul>
  69. 76. <%@ taglib prefix = &quot;yui&quot; uri = &quot;/struts-yui-tags&quot; %> <%@ taglib prefix = &quot;s&quot; uri = &quot;/struts-tags&quot; %> < html > < head > < yui:head datepicker = &quot;true&quot; /> </ head > < body > < p > The selected date is < s:property value = &quot;datepicker&quot; /></ p > < s:form action = &quot;datepicker&quot; > < yui:datepicker id = &quot;datepicker&quot; name = &quot;datepicker&quot; /> < s:submit /> </ s:form > </ body > </ html > datepicker.jsp
  70. 77. < action name = &quot;datepicker&quot; class = &quot;actions.Datepicker&quot; > < result > datepicker.jsp </ result > </ action > struts.xml
  71. 78. public class Datepicker extends ActionSupport { private Date datepicker ; public Date getDatepicker() { return datepicker ; } public void setDatepicker(Date value) { datepicker = value; } } actions.DatePicker.java
  72. 80. Are there other Struts 2 Ajax resources? <ul><li>Turbocharge Your Pages with Ajax, Dojo, and Struts </li></ul><ul><ul><li>( Doug Tillman , http://www.devx.com/webdev/Article/31806 ) </li></ul></ul><ul><li>For help with the Dojo tags, see the new Ajax Recipes page </li></ul><ul><ul><li>http://struts.apache.org/2.x/docs/ajax-and-javascript-recipes.html </li></ul></ul><ul><li>Ian Roughley's (2 nd ) S2 book (Apress) includes an Ajax chapter </li></ul><ul><ul><li>(Practical Apache Struts 2 Web 2.0 Projects, ISBN 1590599039) </li></ul></ul>
  73. 81. Is that all there is? <ul><li>In this session, we covered </li></ul><ul><ul><li>Integrating Ajax with Struts 1 or Struts 2 </li></ul></ul><ul><ul><li>Using the AjaxParts taglib with Struts 1 or 2 </li></ul></ul><ul><ul><li>Using the Ajax YUI plugin with Struts 2 </li></ul></ul>
  74. 82. JSON-P support in APT <ul><li>Simply add jsonp=“true” to any <requestHandler> in ajax-config.xml </li></ul><ul><li>All standard request handlers can be used </li></ul><ul><li>DoNothing will nearly always be the appropriate response handler </li></ul><ul><li>“ Secure” information can be kept in ajax-config.xml </li></ul><ul><li>Dynamic properties in forms </li></ul>
  75. 83. Struts University Series
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×