icefaces and jsf 2.0 on glassfish

44
www.icefaces.org

Upload: eduardo-pelegri-llopart

Post on 20-May-2015

9.426 views

Category:

Technology


3 download

DESCRIPTION

In depth presentation on ICEfaces/JSF on GlassFish. Also includes how to JSF 2.0 will apply to ICEfaces

TRANSCRIPT

Page 1: ICEfaces and JSF 2.0 on GlassFish

www.icefaces.org

Page 2: ICEfaces and JSF 2.0 on GlassFish

www.icefaces.org

ICEfaces is…

Easy Ajax for Java developers

ICEfaces is an Ajax framework that allows developers to easily create rich Internet applications (RIA) in pure Java.

• Open source

• Standards-based

• Extends JavaServer Faces

• Develop rich Web Applications in pure Java, not JavaScript

• Integrated with GlassFish and Friends– Provides NetBeans IDE Plugin

• Endorsed migration for Woodstock users

– Supports Ajax Push applications via Grizzly

– Leverages enterprise capabilities of GlassFish• Security, Scalability: Clustering, Load Balancing and Failover

– Integrates with 3rd Party frameworks and middleware• WebSpace, WebStack

Page 3: ICEfaces and JSF 2.0 on GlassFish

www.icefaces.org

Agenda

• Ajax Push Overview

• Application Programming Basics

• On the Wire

• Code Walkthrough

• Asynchronous Request Processing

• Security

• Custom Components (JSF 1.2 and JSF 2.0)

• JSF 2.0 Ajax

• JSF 2.0 Notable Enhancements

• Summary

Page 4: ICEfaces and JSF 2.0 on GlassFish

www.icefaces.org

Multi-user AuctionMonitor

Page 5: ICEfaces and JSF 2.0 on GlassFish

www.icefaces.org

Multi-user AuctionMonitor

Page 6: ICEfaces and JSF 2.0 on GlassFish

www.icefaces.org

Multi-user AuctionMonitor

Page 7: ICEfaces and JSF 2.0 on GlassFish

www.icefaces.org

Multi-user Locking

Ted selects record for editing

Page 8: ICEfaces and JSF 2.0 on GlassFish

www.icefaces.org

Multi-user Locking

Joe selects same record, requests lock

Page 9: ICEfaces and JSF 2.0 on GlassFish

www.icefaces.org

Multi-user Locking

Ted responds, and accepts or denies

Page 10: ICEfaces and JSF 2.0 on GlassFish

www.icefaces.org

Push in Portlets

Portal page with three portlets

Page 11: ICEfaces and JSF 2.0 on GlassFish

www.icefaces.org

Push in Portlets

Joe searches for a city

Page 12: ICEfaces and JSF 2.0 on GlassFish

www.icefaces.org

Push in Portlets

All three portlets are updated

Page 13: ICEfaces and JSF 2.0 on GlassFish

www.icefaces.org

Ajax Push Illustrated

Ted

Deryk

Server

Page 14: ICEfaces and JSF 2.0 on GlassFish

www.icefaces.org

Ajax Push Illustrated

Ted

Deryk

Server

AjaxRequest

Page 15: ICEfaces and JSF 2.0 on GlassFish

www.icefaces.org

Server

Ajax Push Illustrated

Ted

Deryk

JSF Lifecycle +DOM diff

Page 16: ICEfaces and JSF 2.0 on GlassFish

www.icefaces.org

Ajax Push Illustrated

AjaxResponse

Deryk

Server

AjaxPush

Ted

Page 17: ICEfaces and JSF 2.0 on GlassFish

www.icefaces.org

What is Ajax Push For?

• Distance learning• Collaborative authoring• Auctions• Shared WebDAV filesystem• Blogging and reader comments• SIP-coordinated mobile applications• Hybrid chat/email/discussion forums• Customer assistance on sales/support pages• Multi-step business process made collaborative• Shared trip planner or restaurant selector with maps• Shared calendar, “to do” list, project plan• Games• Enterprise shared record locking and negotiation

Page 18: ICEfaces and JSF 2.0 on GlassFish

www.icefaces.org

Ajax Programming, Ideally.

public class PageBean { String message;

public String getMessage() { return message; }

public void setMessage(String message) { this.message = message; }

}

<f:view xmlns:f=“http://java.sun.com/jsf/core” xmlns:h="http://java.sun.com/jsf/html“ >

<html> <body> <h:form> <h:inputText value=“#{pageBean.message}” /> </h:form> </body> </html>

</f:view>

Presentation Model Declarative User Interface

PageBean.java Page.xhtml

Page 19: ICEfaces and JSF 2.0 on GlassFish

www.icefaces.org

Ajax Push Programming

presentation.setSlide(7);SessionRenderer.render(“GlassFishTV”);

Asynchronously and elsewhere in the application ...

To keep track of groups of users:

SessionRenderer.addCurrentSession(“GlassFishTV”);

Page 20: ICEfaces and JSF 2.0 on GlassFish

www.icefaces.org

Ajax Push Techniques

• Poll– send a request to the server

at some interval– response is “empty” if there is

no update

• Http Streaming– send a request and wait for

response– write “endless” response in

chunks

• Long Poll – send a request to the server

and wait for response– indistinguishable from “slow”

server

Page 21: ICEfaces and JSF 2.0 on GlassFish

www.icefaces.org

Long Polling over HTTP

GET /auctionMonitor/block/receive-updates?icefacesID=1209765435 HTTP/1.1Accept: */*Cookie: JSESSIONID=75CF2BF3E03F0F9C6D2E8EFE1A6884F4Connection: keep-aliveHost: vorlon.ice:18080

Page 22: ICEfaces and JSF 2.0 on GlassFish

www.icefaces.org

Long Polling over HTTP

GET /auctionMonitor/block/receive-updates?icefacesID=1209765435 HTTP/1.1Accept: */*Cookie: JSESSIONID=75CF2BF3E03F0F9C6D2E8EFE1A6884F4Connection: keep-aliveHost: vorlon.ice:18080

Chat message “Howdy”

Page 23: ICEfaces and JSF 2.0 on GlassFish

www.icefaces.org

Long Polling over HTTP

GET /auctionMonitor/block/receive-updates?icefacesID=1209765435 HTTP/1.1Accept: */*Cookie: JSESSIONID=75CF2BF3E03F0F9C6D2E8EFE1A6884F4Connection: keep-aliveHost: vorlon.ice:18080

Chat message “Howdy”

HTTP/1.1 200 OKContent-Type: text/xml;charset=UTF-8Content-Length: 180Date: Tue, 10 Mar 2009 22:49:49 GMTServer: Sun Java System Application Server 9.1_01

<updates> <update address="_id0:_id5:0:chatText"> <span id="_id0:_id5:0:chatText">Howdy</span> </update></updates>

Page 24: ICEfaces and JSF 2.0 on GlassFish

www.icefaces.org

webmc.jspx

<f:view xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html"><html> <head> <title>WebMC</title> </head> <body> <h3>WebMC</h3> <h:form> <h:panelGrid columns="1"> <h:outputText value="Presentation"/> <h:graphicImage value="#{user.slideURL}"/> </h:panelGrid> <h:panelGrid columns="1" > <h:outputText value="Chat"/> <h:outputText value="#{user.chatLog}"/> <h:inputText value="#{user.chatInput}"/> <h:commandButton actionListener="#{user.submit}"/> </h:panelGrid>

Page 25: ICEfaces and JSF 2.0 on GlassFish

www.icefaces.org

UserBean.javapublic class UserBean {

public String getSlideURL() { return slideURL; }

public String getChatLog() { return chatLog; }

public String getChatInput() { return chatInput; }

public void setChatInput(String text) { chatInput = text; append(chatLog, text); }}

Set by presentation moderator slide controls

Page 26: ICEfaces and JSF 2.0 on GlassFish

www.icefaces.org

UserBean.java (Ajax Push)

import com.icesoft.faces.async.render.SessionRenderer;

public class UserBean { String presentationName;

public UserBean() { presentationName = LoginBean.getPresentationName(); SessionRenderer.addCurrentSession(presentationName); }

public void submit() { SessionRenderer.render(presentationName); }}

Page 27: ICEfaces and JSF 2.0 on GlassFish

www.icefaces.org

• Automatic Ajax updates

• No JavaScript Development

• Easy Ajax Component Suite

– No JavaScript component wiring

– No manually defined update regions

• Ajax transport handled by ICEfaces

• Woodstock conversion: utilities and compatible components

• ---

– Asynchronous application-driven browser updates

– All 50+ components are Ajax Push aware

Ajax Components with ICEfaces

Page 28: ICEfaces and JSF 2.0 on GlassFish

www.icefaces.org

A Thread for Every Client?

• Blocking requests with Servlet 2.5 consumes threads

• GlassFish/Grizzly, Tomcat 6, Jetty, and Servlet 3.0 provide asynchronous request processing

• Many connections handled with a small thread pool

Page 29: ICEfaces and JSF 2.0 on GlassFish

www.icefaces.org

GlassFishSuspend with Grizzly.

CometContext context = CometEngine.getEngine().register(contextPath); context.setExpirationDelay(20 * 1000); SuspendableHandler handler = new SuspendableHandler(); handler.attach(response); cometContext.addCometHandler(handler);

class SuspendableHandler implements CometHandler { public void onEvent(CometEvent event) { response.getWriter().println(event.attachment()); cometContext.resumeCometHandler(this);}

presentation.setSlide(7);cometContext.notify(message);

Asynchronously and elsewhere in the application ...

Page 30: ICEfaces and JSF 2.0 on GlassFish

www.icefaces.org

Multiple Applications and Browser Connection Limits

ICEfacesApplication

Ajax PushServer

Glassfish

Asyn

chro

nous

Con

nect

ions

ICEfacesApplicationJMS

Grizzly

http:// host / ajaxpush /

Page 31: ICEfaces and JSF 2.0 on GlassFish

www.icefaces.org

Security for Ajax Push

• Build security in layers– Java– JavaServer Faces– SSL

• Script injection– JavaScript– SQL

• Cross-site request forgery• Cross-site scripting

Page 32: ICEfaces and JSF 2.0 on GlassFish

www.icefaces.org

Custom Components (JSF 1.2)

• Implement MyComponent.java extending UIInput

• Implement MyComponentRenderer.java

• Implement MyComponentTag.java

• Add component and renderer to faces-config.xml

• Add MyComponentTag to TLD

Page 33: ICEfaces and JSF 2.0 on GlassFish

www.icefaces.org

Facelets in JSF 2

• Facelets now part of JSF standard

• Also know as the Page Declaration Language (PDL)‏

• First non-JSP PDL designed for JSF

• Some differences from JSP:– Pages compiled to abstract structure

– Builds JSF component view when executed

– Don't need TLD for tag attributes

– Page templating

• Opens the door for easier component development

Page 34: ICEfaces and JSF 2.0 on GlassFish

www.icefaces.org

Custom Components in JSF 2

• Components built via markup templates

• Also known as composite components

• Composite Component: any Facelet markup file that resides in a resource library

• Custom components can also be developed in Java as per JSF 1.2

Page 35: ICEfaces and JSF 2.0 on GlassFish

www.icefaces.org

Custom Components in JSF 2 (Use)

Page 36: ICEfaces and JSF 2.0 on GlassFish

www.icefaces.org

Custom Components in JSF 2 (Definition)

Page 37: ICEfaces and JSF 2.0 on GlassFish

www.icefaces.org

Ajax in JSF 2.0

• Resource Delivery Mechanism

• Partial View Processing

• Partial View Rendering

• Ajax Client/Server

• Ajax Enabled Components

In JSF 2.0 Spec

In Component Library

Page 38: ICEfaces and JSF 2.0 on GlassFish

www.icefaces.org

Ajax in JSF 2

Restore View

Process Validations

Update Model Values

Ajax Request

execute:4,5

Execute Portion

Partial View Processing

Apply Request Values

InvokeApplication

RenderResponse1

2 3

544 5

Page 39: ICEfaces and JSF 2.0 on GlassFish

www.icefaces.org

Ajax in JSF 2

Restore View

Process Validations

Update Model Values

Ajax Request

render:4,5

Partial View Rendering

Apply Request Values

InvokeApplication

RenderResponse

Render Portion

1

2 3

544 5

Page 40: ICEfaces and JSF 2.0 on GlassFish

www.icefaces.org

Ajax in JSF 2

• Standard JavaScript API– jsf.ajax.request, jsf.ajax.response– jsf.ajax.addOnError, jsf.ajax.addOnEvent– jsf.getProjectStage, jsf.getViewState

• Standard Response Format– XML based– “instruction set” for:

– updating DOM, attribute changes, script execution– inserting into DOM, deleting DOM nodes, extensions

• Standard Subtree Execution and Rendering– frameworks may also plug in their own traversal strategy

• Declarative Ajax (f:ajax)‏• Net result is Ajax component interoperability

Page 41: ICEfaces and JSF 2.0 on GlassFish

www.icefaces.org

Enhancements in JSF 2

• System Events– Represent specific points in time for a JSF application– For example, listen for:

– when a component was added to parent– when a component is about to be rendered

– Listeners implement javax.faces.event.SystemEventListener

• “view” scope– allows attributes to be associated with a view– attributes persist until a new view is navigated to– can be accessed via EL (like request or session)‏

• Annotations– An alternative to XML configuration– @FacesComponent, @FacesConverter, @ManagedBean– @RequestScoped, @SessionScoped, @ApplicationScoped

Page 42: ICEfaces and JSF 2.0 on GlassFish

www.icefaces.org

Enhancements in JSF 2

• Resources– Facility for serving resources (CSS, JavaScript, images, etc..)‏– Can be packaged under web application

– Under “resources” directory– Or into classpath under META-INF/resources

– Typically reside in libraries– Resources can be versioned

• Exceptions– Exception handling facility allows queuing of exceptions– Also leverages System Event facility– publish ExceptionEvent(s); subscribe to ExceptionEvent(s)‏

Page 43: ICEfaces and JSF 2.0 on GlassFish

www.icefaces.orgICESOFT TECHNOLOGIES INC. www.icefaces.org

SummaryThe Asynchronous Web Revolution is Now

• Ajax Push will revolutionize human interaction

• Ajax Push is the key to enterprise collaboration for the Web

• JSF 2.0 is the language for developing web applications

• Ajax Push can scale on GlassFish with Asynchronous Request Processing

• ICEfaces provides the high-level capabilities for enterprise collaboration features in your application

Page 44: ICEfaces and JSF 2.0 on GlassFish

www.icefaces.org44

Thank You

Contact Us:Toll Free: +1 877 263 3822 USAInternational: +1 403 663 [email protected]