Portlets and Ajax: Building More Dynamic Web Apps

Similar documents
JSR-286: Portlet Specification 2.0

Advanced Web Systems 4- PORTLET API specifications (JSR 286) A. Venturini

JSR-286: Portlet Specification 2.0

Portlet Standard JSR 168 / JSR 286

AJAX Programming Chris Seddon

Advanced Software Engineering

An Introduction to AJAX. By : I. Moamin Abughazaleh

Session 11. Ajax. Reading & Reference

JavaServer Faces Technology, AJAX, and Portlets: It s Easy if You Know How!

AJAX: Introduction CISC 282 November 27, 2018

Ajax- XMLHttpResponse. Returns a value such as ArrayBuffer, Blob, Document, JavaScript object, or a DOMString, based on the value of

What's New in the Servlet and JavaServer Pages Technologies?

Advanced Topics in WebSphere Portal Development Graham Harper Application Architect IBM Software Services for Collaboration

Portlets (JSR-168) Dave Landers. BEA Systems, Inc. Dave Landers Portlets (JSR-168)

JavaScript CoAPRequest API

Ajax and JSF: Natural Synergy

AJAX: The Basics CISC 282 March 25, 2014

AJAX: The Basics CISC 282 November 22, 2017

Contents. Demos folder: Demos\14-Ajax. 1. Overview of Ajax. 2. Using Ajax directly. 3. jquery and Ajax. 4. Consuming RESTful services

Session 18. jquery - Ajax. Reference. Tutorials. jquery Methods. Session 18 jquery and Ajax 10/31/ Robert Kelly,

Programming for Digital Media. Lecture 7 JavaScript By: A. Mousavi and P. Broomhead SERG, School of Engineering Design, Brunel University, UK

Introduction to Ajax

Improve and Expand JavaServer Faces Technology with JBoss Seam

Standards and the Portals Project

Asynchronous Ajax for Revolutionary Web Applications. Jeanfrancois Arcand Ted Goddard, Ph.D.

A.A. 2008/09. What is Ajax?

Module7: AJAX. Click, wait, and refresh user interaction. Synchronous request/response communication model. Page-driven: Workflow is based on pages

Sang Shin. Java Portlets (JSR-168) Revision History. Disclaimer & Acknowledgments

Using Adobe Flex in JSR-286 Portlets

Fall Semester (081) Module7: AJAX

AJAX ASYNCHRONOUS JAVASCRIPT AND XML. Laura Farinetti - DAUIN

Lotus Exam IBM Websphere Portal 6.1 Application Development Version: 5.0 [ Total Questions: 150 ]

Tooling for Ajax-Based Development. Craig R. McClanahan Senior Staff Engineer Sun Microsystems, Inc.

eclipse rich ajax platform (rap)


Best Practices for JSF Portlet Migration and Development

IBM Realtests LOT-911 Exam Questions & Answers

GWT and jmaki: Expanding the GWT Universe. Carla Mott, Staff Engineer, Sun Microsystems Greg Murray, Ajax Architect, Sun Microsystems

Introduction to Ajax. Sang Shin Java Technology Architect Sun Microsystems, Inc.

A Closer Look at XPages in IBM Lotus Domino Designer 8.5 Ray Chan Advisory I/T Specialist Lotus, IBM Software Group

WA2089 WebSphere Portal 8.0 Programming EVALUATION ONLY

10.1 Overview of Ajax

Session 11. Calling Servlets from Ajax. Lecture Objectives. Understand servlet response formats

Adding Telephony to Java Technology-Based Enterprise Applications

Beyond the Portlet API

Ajax in Oracle JDeveloper

AJAX Basics. Welcome to AJAX Basics presentation. My name is Sang Shin. I am Java technology architect and evangelist from Sun Microsystems.

Liferay 7 Portlet to Empower Your Custom Development

Asynchronous JavaScript + XML (Ajax)

Ajax. Ronald J. Glotzbach

Developing Applications for IBM WebSphere Portal 7.0


IBM Exam C IBM WebSphere Portal 8.5 Solution Development Version: 6.1 [ Total Questions: 59 ]

CS 5142 Scripting Languages

Code Examples Using Java ME Technology and New Web 2.0 Services (Beyond Google Maps)

PROCE55 Mobile: Web API App. Web API.

Oracle Developer Day

EBS goes social - The Triumvirate Liferay, Application Express and EBS

Building JSR-286 portlets using AngularJS and IBM Web Experience Factory

Seam 3. Pete Muir JBoss, a Division of Red Hat

Term Paper. P r o f. D r. E d u a r d H e i n d l. H o c h s c h u l e F u r t w a n g e n U n i v e r s i t y. P r e s e n t e d T o :

SOFTWARE DEVELOPMENT SERVICES WEB APPLICATION PORTAL (WAP) TRAINING. Intuit 2007

jmaki Overview Sang Shin Java Technology Architect Sun Microsystems, Inc.

Oracle Coherence and WebLogic 12c Delivering Real Time Push at Scale Steve Millidge

RIA Security - Broken By Design. Joonas Lehtinen IT Mill - CEO

A synchronous J avascript A nd X ml

Implementing JSR 168 inter-portlet communication using Rational Application Developer V6.0 and WebSphere Portal V5.1

Ajax HTML5 Cookies. Sessions 1A and 1B

The Future of the Web: HTML 5, WebSockets, Comet and Server Sent Events

Developing Ajax Web Apps with GWT. Session I

WSRP Web Services for Remote Portlets

IT Certification Exams Provider! Weofferfreeupdateserviceforoneyear! h ps://

2/6/2012. Rich Internet Applications. What is Ajax? Defining AJAX. Asynchronous JavaScript and XML Term coined in 2005 by Jesse James Garrett

Oracle WebLogic Portal

Ajax or AJAX? The acronym AJAX has changed to the term Ajax, which does not represent specific technologies

WebSphere Portal Application Development Best Practices using Rational Application Developer IBM Corporation

COPYRIGHTED MATERIAL. AJAX Technologies. Google Suggest

Programming Web Apps for Tiny Devices with Java Card 3.0 Connected Edition

Web Application Development Using Spring, Hibernate and JPA

PASS4TEST. IT Certification Guaranteed, The Easy Way! We offer free update service for one year

quiz 1 details wed nov 17, 1pm see handout for locations covers weeks 0 through 10, emphasis on 7 onward closed book bring a , 2-sided cheat she

Introduction to Web Application Development Using JEE, Frameworks, Web Services and AJAX

An update on the latest strategies for building Ajax applications with JavaServer Faces

Liferay Faces. Reference Documentation ga4

AD105 Introduction to Application Development for the IBM Workplace Managed Client

AJAX. Introduction. AJAX: Asynchronous JavaScript and XML

Developing Applications with Java EE 6 on WebLogic Server 12c

Web Programming Step by Step

AJAX: Rich Internet Applications

AJAX. Lecture 26. Robb T. Koether. Fri, Mar 21, Hampden-Sydney College. Robb T. Koether (Hampden-Sydney College) AJAX Fri, Mar 21, / 16

JSF 2.0: Insight and Opinion

Lesson 12: JavaScript and AJAX

AJAX and Persistence: Emerging Patterns and Pain Points

Web Application Development Using Spring, Hibernate and JPA

Connecting the RISC Client to non-javascriptinterfaces

Using the Visualization API with GWT and Other Advanced Topics. Itai Raz May 27, 2009

1 Announcements (0:00 2:00) 2

de la session Portal 6.1 Administration

Enriching Portal user experience using Dojo toolkit support in IBM Rational Application Developer v8 for IBM WebSphere Portal

Vendor: Liferay. Exam Code: LRP-614. Exam Name: Liferay Certified Professional Developer. Version: Demo

Transcription:

Portlets and Ajax: Building More Dynamic Web Apps Subbu Allamaraju Senior Staff Engineer BEA Systems, Inc. TS-4003 2007 JavaOne SM Conference Session TS-4003

Goals Goals of the of Session the Session Learn how to build dynamic and heterogeneous portlet apps with Java Specification Request (JSR) 286 and Ajax. 2007 JavaOne SM Conference Session TS-4003 2

Agenda JSR 168 and Ajax Rights, Wrongs, and Relevance Overview of JSR 286 New Features Ajax and JSR 286 How Far Does the Spec Go? Framework Integration Dojo as an Example 2007 JavaOne SM Conference Session TS-4003 3

Agenda JSR 168 and Ajax Rights, Wrongs, and Relevance Overview of JSR 286 New Features Ajax and JSR 286 How Far Does the Spec Go? Framework Integration Dojo as an Example 2007 JavaOne SM Conference Session TS-4003 4

JSR 168 View of a Web App Action request processaction Controller logic goes here Render request render View goes here Simple lifecycle with clear separation of concerns 2007 JavaOne SM Conference Session TS-4003 5

JSR 168 and Ajax: Example Portlet UI Form 2007 JavaOne SM Conference Session TS-4003 6

JSR 168 and Ajax: Example Ajax request using an Action URL Process the request here processaction Write some UI/data render Full portal page Portals inject other stuff 2007 JavaOne SM Conference Session TS-4003 7

JSR 168 and Ajax The pitfalls Action and render URLs point to the portal Not to the portlet Render output is meant for aggregation Portals add more markup to the response i.e., scripts can t process the response Can t scrape the response? Contradicts with XMLHttpRequest s view XMLHttpRequest is a client API and wants to consume the response itself 2007 JavaOne SM Conference Session TS-4003 8

JSR 168 Work-Around Ajax request using an Action URL Process the request here processaction Render portlet render Full portal page Ajax request to a servlet Ajax response Copy/share context Servlet 2007 JavaOne SM Conference Session TS-4003 9

JSR 168 Work-Around Things to watch out for Shared context can become stale or invalid Make sure that the servlet end point is reachable from browsers Particularly when portlets are remoted via protocols like WSRP (Web Services for Remote Portlets), or when you are moving portlets around 2007 JavaOne SM Conference Session TS-4003 10

Agenda JSR 168 and Ajax Rights, Wrongs, and Relevance Overview of JSR 286 New Features Ajax and JSR 286 How Far Does the Spec Go? Framework Integration Dojo as an Example 2007 JavaOne SM Conference Session TS-4003 11

JSR 286: Key Changes A more pragmatic API Improved support for bridges Portlet request and response wrappers Portlet filters Loosely coupled coordination Server-side events Shared render parameters Serving resources Generate arbitrary response 2007 JavaOne SM Conference Session TS-4003 12

Event-Based Coordination Step 1: Event source public class EmployeePortlet extends GenericPortlet { public void processaction(actionrequest req, ActionResponse resp) { // Process the request... EmplBean emplbean = new EmplBean( ); // Fire an event resp.setevent( emplcreated, emplbean);... 2007 JavaOne SM Conference Session TS-4003 13

Event-Based Coordination Step 2: Declare interest in events <portlet>... <supported-processing-event>emplcreated</supportedprocessing-event> </portlet> <event-definition> <name>emplcreated</name> <java-class>samples.emplbean</java-class> </event-definiton> 2007 JavaOne SM Conference Session TS-4003 14

Event-Based Coordination Step 3: Event target public class NewEmployeePortlet extends GenericPortlet { public void processevent(eventrequest req, EventResponse resp) { Event e = req.getevent(); EmplBean emplbean = (EmpBean) e.getvalue();... public void render(renderrequesr req, RenderResponse resp) {... 2007 JavaOne SM Conference Session TS-4003 15

Shared Render Parameters Step 1: Set a render parameter public class ZipSelector extends GenericPortlet { public void processaction(actionrequest req, ActionResponse resp) { resp.setrenderparameter( zip, 12345 );... OR <portlet:renderurl var= url ><param name= zip value= 12345 /></portlet:renderurl> 2007 JavaOne SM Conference Session TS-4003 16

Shared Render Parameters Step 2: Receive a render parameter public class MapsPortlet extends GenericPortlet { public void render(renderrequest req, RenderResponse resp) { String zip = req.getparameter( zip);...... 2007 JavaOne SM Conference Session TS-4003 17

Resource Serving <portlet:resourceurl var= url > <portlet:param name= p1 value= v1 /> </portlet:resourceurl/> <img src= <%=url%> alt=... /> public class ChartPortlet extends GenericPortlet { public void serveresource(resourcerequest req, ResourceResponse resp) { // Write the chart resp.setcontenttype( img/gif ); resp.getoutputstream().write(...);... Resource requests are idempotent 2007 JavaOne SM Conference Session TS-4003 18

Agenda JSR 168 and Ajax Rights, Wrongs, and Relevance Overview of JSR 286 New Features Ajax and JSR 286 How Far Does the Spec Go? Framework Integration Dojo as an Example 2007 JavaOne SM Conference Session TS-4003 19

JSR 286 + Ajax: How Far? Future or Extensions Non-idempotent Ajax Requests Events Shared render parameter changes Container/portal managed state JSR 286 Idempotent Ajax Requests Partial updates to the portlet s UI Form submissions or state changes possible Cannot change container/portal managed state 2007 JavaOne SM Conference Session TS-4003 20

serveresource() for Ajax Look familiar? Ajax request using an Action URL Process the request here processaction Render full portlet render Full portal page Ajax request using a resource URL Ajax response serveresource 2007 JavaOne SM Conference Session TS-4003 21

Using serveresource() for Ajax Step 1: Client-side <portlet:resourceurl var= url ><param name= p1 value= v1 /> </portlet:resourceurl> <script type= text/javascript > var req = new XMLHttpRequest(); req.onreadystatechange = function() { // Update UI req.open( GET, <%=url%>); req.send(); <script> 2007 JavaOne SM Conference Session TS-4003 22

Using serveresource() for Ajax Step 2: Server-side public class MyPortlet extends GenericPortlet { public void serveresource(resourcerequest req, ResourceResponse resp) { // Process request and write some JSO data resp.setcontenttype( application/json ); resp.getwriter().write(... ); 2007 JavaOne SM Conference Session TS-4003 23

serveresource Programming Model For traditional requests, continue to use action/render URLs For Ajax requests, use resource URLs Advantages Easy to migrate existing JSR 168 applications Works with existing client-side libraries Addresses all idempotent use cases 2007 JavaOne SM Conference Session TS-4003 24

serveresource and State Management Portlet UI fragment serveresource View State (e.g., in HTTP session) Full page refresh Portlet UI fragment render 2007 JavaOne SM Conference Session TS-4003 25

Non-Idempotent Ajax Requests Why special? Client requests have ripple effects Portlet s state and view Other portlets state and view Portal s state and view Portal and the container need to collaborate on the server-side as well as the client-side Not addressed, but leaves the door open 2007 JavaOne SM Conference Session TS-4003 26

Unwrap response An Approach Server-side Portlet Portlet Portlet Portlet Portlet Portlet Client-side 2007 JavaOne SM Conference Session TS-4003 27

An Approach 1. Use the existing JSR 168/JSR 286 APIs i.e., take full advantage of the container 2. Use a wrapped XMLHttpRequest For all browser-server I/O Portal provides an implementation of the wrapped XMLHttpRequest 2007 JavaOne SM Conference Session TS-4003 28

XMLPortletRequest A Wrapper over XMLHttpRequest (*) interface XMLPortletRequest { attribute EventListener onreadystatechange; readonly attribute unsigned short readystate; void open(method, url, async, user, password); void setrequestheader(header, value); void send(data); void abort(); DOMString getallresponseheaders(); DOMString getresponseheader(header); readonly attribute DOMString responsetext; readonly attribute Document responsexml; readonly attribute unsigned short status; readonly attribute DOMString statustext; * http://www.w3.org/tr/xmlhttprequest 2007 JavaOne SM Conference Session TS-4003 29

XMLPortletRequest Example <script type= text/javascript > var request = null; try { request = new XMLPortletRequest(); catch(e) { request = new XMLHttpRequest(); request.onreadystatechange = function() { if(request.readystate == 4 && request.status == 200) { // Process responsexml or responsetext request.open( GET, <%=url%>, false); request.send(null); </script> 2007 JavaOne SM Conference Session TS-4003 30

XMLPortletRequest Key properties Least invasive Semantically and syntactically equivalent to the familiar XMLHttpRequest i.e., no need to learn/write portal/portlet-specific JavaScript technology Ajax frameworks can be adopted for use in portals Designed as an XMLHttpRequest-equivalent for portlets Ajax requests are portal-managed Portals implement XMLPortletRequest Portals can update other portlets on the page Ajax requests get full benefits of the portlet API 2007 JavaOne SM Conference Session TS-4003 31

Server-Side Portlet API Use existing JSR 168/JSR 286 APIs A well-defined extension Request attributes Standard behavior: unspecified Ajax: Request attributes are preserved between processaction and the first render Render URL parameters Standard behavior: Replace current render parameters Ajax: Do not replace current render parameters JSR 286 allows such extensions to be declared and queried at runtime 2007 JavaOne SM Conference Session TS-4003 32

DEMO Events and Ajax 2007 JavaOne SM Conference Session TS-4003 33

Agenda JSR 168 and Ajax Rights, Wrongs, and Relevance Overview of JSR 286 New Features Ajax and JSR 286 How Far Does the Spec Go? Framework Integration Dojo as an Example 2007 JavaOne SM Conference Session TS-4003 34

Ajax Frameworks and Portlets Frameworks make Ajax development easy Client-side frameworks Dojo, prototype, etc. Server-side frameworks JavaServer Faces technology-oriented frameworks like ICEFaces, Backbase, etc. GWT, DWR, etc. Can these toolkits be used for portlet development? Depends Work in progress 2007 JavaOne SM Conference Session TS-4003 35

Adopting an Ajax Framework Example: Dojo dojo.hostenv.getxmlhttpobject = function() { try{ http = new XMLPortletRequest(); catch(e) {... // Rest of the code to create XMLHttpRequest try { http = new XMLHttpRequest; catch(e) {... return http; 2007 JavaOne SM Conference Session TS-4003 36

Adopting an Ajax Framework Example: Dojo in a portlet dojo.io.bind({ url: <%=url%>", method : "GET", mimetype: "application/json", load: function(type, data) {..., error: function(type, error) {... ); 2007 JavaOne SM Conference Session TS-4003 37

Framework Selection for Portlet Development If writing portlets natively Rely on serveresouce to the extent possible Portability, by limiting the use cases Use extensions like XMLPortletRequest for more complex use cases Vendors are likely to offer other kinds of extensions If writing portlets using Ajax frameworks Portability may not be guaranteed yet More standardization efforts are on the horizon 2007 JavaOne SM Conference Session TS-4003 38

Summary JSR 168 and Ajax Limited support JSR 286 and Ajax Provides a basic solution for idempotent Ajax requests Meets most common use cases Leaves the door open for vendor extensions 2007 JavaOne SM Conference Session TS-4003 39

Q&A subbu@bea.com 2007 JavaOne SM Conference Session TS-4003 40

Portlets and Ajax: Building More Dynamic Web Apps Subbu Allamaraju Senior Staff Engineer BEA Systems, Inc. TS-4003 2007 JavaOne SM Conference Session TS-4003