RichFaces 4 Webinar - New and Advanced Features

70
Exadel RichFaces 4 Webinar Series Webinar #3: New and Advanced Features June 15, 2011 Max Katz Charley Cowens http://exadel.com/web/portal/webinars

description

RichFaces 4 webinar series. Webinar #3: RichFaces 4 - New and Advanced Features. Presented on June 15, 2011

Transcript of RichFaces 4 Webinar - New and Advanced Features

Page 1: RichFaces 4 Webinar - New and Advanced Features

Exadel

RichFaces 4 Webinar Series

Webinar #3: New and Advanced Features

June 15, 2011

Max KatzCharley Cowenshttp://exadel.com/web/portal/webinars

Page 2: RichFaces 4 Webinar - New and Advanced Features

Exadel

RichFaces 4 Webinar Series

http://exadel.com/web/portal/webinars

RichFaces 4 – Everything You Need to KnowPresented on April 20, 2011

RichFaces 3 to RichFaces 4 — A Class in Moving UpPresented on May 11, 2011

Page 3: RichFaces 4 Webinar - New and Advanced Features

Exadel

Max Katz

● Senior Systems Engineer

● JSF, RichFaces, Java EE consulting, and training

● Manages exadel.org – Exadel's open source projects and community

● Community manager for gotiggr.com – tool for creating and sharing interactive web and mobile HTML prototypes

Page 4: RichFaces 4 Webinar - New and Advanced Features

Exadel

Author of Practical RichFaces

(Apress)

4

Lead-author of Practical RichFaces, 2/e

(Apress, July 2011)

Summer 2011

Page 5: RichFaces 4 Webinar - New and Advanced Features

Exadel

Page 6: RichFaces 4 Webinar - New and Advanced Features

Exadel

Exadel is a global software engineering company.● Founded in 1998,

headquarters in San Francisco Bay Area

● 7 development offices in Europe

● 350+ employees

Page 7: RichFaces 4 Webinar - New and Advanced Features

Exadel

What Exadel DoesServices● Professional services, rich enterprise

application development, Eclipse development, custom rich component development, mobile development, training

Products

● Open source with JBoss: RichFaces, JBoss Tools/JBoss Developer Studio; exadel.org: Flamingo, Fiji, jsf4birt, JavaFX Plug-in for Eclipse; gotiggr.com– interactive Web and mobile HTML prototypes

Page 8: RichFaces 4 Webinar - New and Advanced Features

Exadel

The Plan Is Simple

1) Super quick introduction to RichFaces 4 (promise)

2) Show you some of the new and advanced features in RichFaces 4

Page 9: RichFaces 4 Webinar - New and Advanced Features

Exadel

RichFaces 4 is a lightweight, open source framework for

JSF 2

Official RichFaces logo

Page 10: RichFaces 4 Webinar - New and Advanced Features

Exadel

RichFaces 4 – Rich JSF Framework

● UI components

◦ a4j:* tag library (core)

◦ rich:* tag library (UI)

◦ Components' JavaScript API

● Client-side validation (Bean Validation based)

● Skins

● CDK – Component Development Kit

Page 11: RichFaces 4 Webinar - New and Advanced Features

Exadel

RichFaces 4

100% built on top of JSF2, just extends functionality in

JSF 2

Page 12: RichFaces 4 Webinar - New and Advanced Features

Exadel

RichFaces 4

JavaScript functionality is now entirely based on the

popular jQuery library

Page 13: RichFaces 4 Webinar - New and Advanced Features

Exadel

RichFaces 4

● All components are reviewed for consistency, usability

● Redesigned following semantic HTML principles

● Server-side and client-side performance optimization

● Strict code clean-up and review

Page 14: RichFaces 4 Webinar - New and Advanced Features

Exadel

RichFaces 4

New client-side validation based on Bean Validation

(JSR 303)

Page 15: RichFaces 4 Webinar - New and Advanced Features

Exadel

RichFaces 4

New and easy-to-use CDK (Component Development Kit),

allows you to quickly build your own custom rich

components

Page 16: RichFaces 4 Webinar - New and Advanced Features

Exadel

RichFaces 4

Runs on: Tomcat 6/7, Resin, JBoss AS 6/7, GlassFish 3.x,

WebLogic

(runs on any server where JSF 2 application

can be deployed)

Page 17: RichFaces 4 Webinar - New and Advanced Features

Exadel

RichFaces 4

Runs on: Google App Engine (GAE), Amazon EC2,

CloudBees

Page 18: RichFaces 4 Webinar - New and Advanced Features

Exadel

RichFaces 4

JSF implementations: Mojarra or Myfaces

Page 19: RichFaces 4 Webinar - New and Advanced Features

Exadel

RichFaces 4

Zero-configuration, just drop RichFaces libraries into the

application

Page 20: RichFaces 4 Webinar - New and Advanced Features

Exadel

RichFaces 4

Any browser

Page 21: RichFaces 4 Webinar - New and Advanced Features

Exadel

RichFaces 4

Tooling support through JBoss Tools, IntelliJ,

NetBeans

Page 22: RichFaces 4 Webinar - New and Advanced Features

Exadel

RichFaces Versions

Version JSF 1.1 JSF 1.2 JSF 2

RichFaces 3.1.x •RichFaces 3.3.3* • •RichFaces 4 •* Note: RichFaces 3.3.3 has basic JSF 2 support

Page 23: RichFaces 4 Webinar - New and Advanced Features

Exadel

RichFaces Core

Page 24: RichFaces 4 Webinar - New and Advanced Features

Exadel

<table> ... <td onmouseover="update('yellow')"/> ...</table>

<h:form> <a4j:jsFunction name="update" action="#{bean.change}" render="..."> <a4j:param value="param1" assignTo="#{bean.color}"/> </a4j:jsFunction></h:form>

<a4j:jsFunction> – fire Ajax request from any JavaScript function, HTML event

Page 25: RichFaces 4 Webinar - New and Advanced Features

Exadel

<h:commandButton action="#{bean.change}"> <a4j:ajax render="id"/></h:commandButton>

If you had to pick just one Ajax control, you would want <a4j:jsFunction>

<h:commandButton onclick="sendAjax();"/>

<a4j:jsFunction name="sendAjax" action="#{bean.change}" render="id"/>

Is the same as:

Page 26: RichFaces 4 Webinar - New and Advanced Features

Exadel

<a4j:outputPanel> – auto rendered panel<a4j:commandButton value="Save" action="#{bean.save}"><a4j:commandButton value="Edit" action="#{bean.edit}">

<a4j:outputPanel ajaxRendered="true"> <h:panelGrid> ... </h:panelGrid></a4j:outputPanel>

<a4j:outputPanel ajaxRendered="true"> <rich:dataTable> ... </rich:dataTable></a4j:outputPanel>

Page 27: RichFaces 4 Webinar - New and Advanced Features

Exadel

Turning off auto rendered panels

<a4j:commandButton value="Save" action="#{bean.save}"><a4j:commandButton value="Edit" action="#{bean.edit}" render="edit" limitRender="true">

<a4j:outputPanel ajaxRendered="true"> <h:panelGrid> ... </h:panelGrid></a4j:outputPanel><h:panelGrid id="edit"> <rich:dataTable> ... </rich:dataTable></h:panelGrid>

Page 28: RichFaces 4 Webinar - New and Advanced Features

Exadel

render=”#{bean.renderList}”

1) Ajax request sent

2) Component IDs to be rendered resolved

3) Component IDs are rendered into the page

4) 2nd Ajax request is sent. In this request the components (resolved in step 2 are sent with request) will be rendered

1) Ajax request sent

2) Component IDs to be rendered resolved

3) Component IDs are rendered

JSF RichFaces

Page 29: RichFaces 4 Webinar - New and Advanced Features

Exadel

<a4j:queue> – “combining” events from the same component

While a request is executing on the server, all requests from button A or button B will be combined (merged) if the last event in the queue is of the same type.

<a4j:queue />...<a4j:commandButton id="buttonA" value="Button A"/><a4j:commandButton id="buttonB" value="Button B"/>

Page 30: RichFaces 4 Webinar - New and Advanced Features

Exadel

<a4j:queue> – “combining” events from different components

<a4j:queue /><a4j:commandButton id="buttonA" value="Button A"> <a4j:attachdQueue requestGroupingId="ajaxGroup"/></a4j:commandButton><a4j:commandButton id="buttonB" value="Button B"> <a4j:attachdQueue requestGroupingId="ajaxGroup"/></a4j:commandButton>

While a request is executing on the server, all requests from button A or button B will be combined (merged).

Page 31: RichFaces 4 Webinar - New and Advanced Features

Exadel

<a4j:queue> – setting request delay allows “waiting” for requests from same component in order to merge events

<a4j:queue requestDelay="1000"/>

<a4j:commandButton id="buttonA" value="Button A"> <a4j:attachdQueue requestDelay="2000"/></a4j:commandButton>

<a4j:commandButton id="buttonB" value="Button B"/>

Page 32: RichFaces 4 Webinar - New and Advanced Features

Exadel

Skipping phases when validating

<h:inputText id="name" value="#{bean.name}"/> <a4j:ajax event="blur" bypassUpdates="true"/></h:inputText><rich:message for="name"/>

1.Restore View2.Apply Request Values3.Process Validation4.Update Model5.Invoke Application6.Render Response

Page 33: RichFaces 4 Webinar - New and Advanced Features

Exadel

Invoking JavaScript functions during Ajax request

<a4j:commandLink value="Save" onbegin="ajaxOnBegin()" onbeforedomupdate="ajaxOnBeforeDomUpdate()" oncomplete="ajaxOnComplete()"></a4j:commandLink>

Supported by all action components in RichFaces

Page 34: RichFaces 4 Webinar - New and Advanced Features

Exadel

<a4j:log> – Ajax request/response information, logging

Page 35: RichFaces 4 Webinar - New and Advanced Features

Exadel

<a4j:param> - like <f:param>, but simpler as it also assigns the value to a bean property automatically

<a4j:commandButton value="Save"> <a4j:param value="1009" assignTo="#{bean.product}"/></a4j:commandButton>

public class Bean { private String product; public void setProduct (String product) {...}}

Page 36: RichFaces 4 Webinar - New and Advanced Features

Exadel

Another great feature is that <a4j:param> value can contain any JavaScript expression or JavaScript function, when noEscape="true"

<a4j:param name="width" value="screen.width" assignTo="#{bean.screenWidth}" noEscape="true" />

Page 37: RichFaces 4 Webinar - New and Advanced Features

Exadel

RichFaces UI: Components and Functions

Page 38: RichFaces 4 Webinar - New and Advanced Features

Exadel

<rich:popupPanel> can be modal and non-modal

<rich:popupPanel modal="false"> <f:facet name="header"> Edit User </f:facet> ... ...</rich:popupPanel>

Page 39: RichFaces 4 Webinar - New and Advanced Features

Exadel

Many RichFaces components provide client-side JavaScript API

Method name Description

getTop() Return the top co-ordinate for the position of the pop-up panel.

getLeft() Return the left co-ordinate for the position of the pop-up panel.

moveTo(top,left) Move the pop-up panel to the co-ordinates specified with the top and left parameters.

resize(width,height) Resize the pop-up panel to the size specified with the width and height parameters.

show() Show the pop-up panel.

hide() Hide the pop-up panel.

<rich:popupPanel> JavaScript API

Page 40: RichFaces 4 Webinar - New and Advanced Features

Exadel

Invoking component JavaScript API using #{rich:component(id)} function

<input type="button" onclick="#{rich:component('popup')}.show();"

value="Open" />

<rich:popupPanel id="popup"> <h:outputLink value="#"

onclick="#{rich:component('popup')}.hide(); return false;">

<h:outputText value="Close"/> </h:outputLink></rich:popupPanel>

Page 41: RichFaces 4 Webinar - New and Advanced Features

Exadel

Invoking component JavaScript API using <rich:componentControl> component<h:outputLink value="#"> <h:outputText value="Open" /> <rich:componentControl event="click" target="popup" operation="show" /></h:outputLink>

<rich:popupPanel header="RichFaces" id="popup"> <h:outputLink value="#"> <h:outputText value="Close" /> <rich:componentControl event="click" target="popup" operation="hide" /> </h:outputLink></rich:popupPanel>

Page 42: RichFaces 4 Webinar - New and Advanced Features

Exadel

<rich:accordion id="c"> <rich:accordionItem header="New York" name="nyc"> <h:outputText value="You selected New York"/> </rich:accordionItem> <rich:accordionItem header="San Francisco" name="sf"> <h:outputText value="You selected San Francisco"/> </rich:accordionItem> ...</rich:accordion>

Page 43: RichFaces 4 Webinar - New and Advanced Features

Exadel

<input type="button" value="New York City" onclick="#{rich:component('c')}.switchToItem('nyc')"/><input type="button" value="San Francisco" onclick="#{rich:component('c')}.switchToItem('sf')"/><input type="button" value="Los Angeles" onclick="#{rich:component('c')}.switchToItem('la')"/>

<input type="button" value="First" onclick="#{rich:component('c')}.switchToItem('@first')"/><input type="button" value="Next" onclick="#{rich:component('c')}.switchToItem('@next')"/><input type="button" value="Previous" onclick="#{rich:component('c')}.switchToItem('@prev')"/><input type="button" value="Last" onclick="#{rich:component('c')}.switchToItem('@last')"/>

Page 44: RichFaces 4 Webinar - New and Advanced Features

Exadel

RichFaces client functions

Function Description

rich:client(id) Returns component client id

rich:element(id) Returns DOM element

rich:component(id)Returns RichFaces client component instance to call JS API method

rich:isUserInRole(role) Returns if the user has specified role

rich:findComponent(id)Returns component instance for given short id

Page 45: RichFaces 4 Webinar - New and Advanced Features

Exadel

Standard Java EE security with #{rich:isUserInRole(role)} function

<rich:panel header="Admin panel" rendered="#{rich:isUserInRole('admin')}"> Very sensitive information</rich:panel>

<rich:panel header="User panel"> General information</rich:panel>

● Calls this method:

facesContext.getExternalContext.getUserInRole(role)

● What's good is that security roles can be defined anywhere

Page 46: RichFaces 4 Webinar - New and Advanced Features

Exadel

RichFaces data iteration components support partial updates

render="@row"

render="@column"render="@header"

render="@footer"

render="@body"

render="cellId"

To render from outside the table:render="tableId@header"render="tableId@body"render="tableId@footer"

Page 47: RichFaces 4 Webinar - New and Advanced Features

Exadel

Deciding what rows/cell to update in run-time

render="tableId:rows(bean.rowsSet)"

render="tableId:rows(bean.rowsSet):cellId"

Page 48: RichFaces 4 Webinar - New and Advanced Features

Exadel

New collapsible sub table component

Page 49: RichFaces 4 Webinar - New and Advanced Features

Exadel

<rich:dataTable> supports column and row spanning

Page 50: RichFaces 4 Webinar - New and Advanced Features

Exadel

New <rich:list> component, can be easily rendered as ordered, unordered, or definitions

<rich:list id="cities" value="#{bean.cityList}" var="city" type="#{bean.listType}"> <f:facet name="term">

<h:outputText value="#{city.country}" /> </f:facet> <h:outputText value="#{city.name} " /> ...</rich:list>

Page 51: RichFaces 4 Webinar - New and Advanced Features

Exadel

Using jQuery with <rich:jQuery>

<input type="button" id=" value="Update panel"/><rich:jQuery selector="#changeButton" event="click" query="$('#nycInfo .rf-p-hdr').text('New York City'); $('.rf-p-b').css('color', 'blue');" />

Page 52: RichFaces 4 Webinar - New and Advanced Features

Exadel

Using jQuery when page rendered to create zebra-like styling for table

Page 53: RichFaces 4 Webinar - New and Advanced Features

Exadel

<style> .even-row { background-color: #FCFFFE; } .odd-row { background-color: #ECF3FE; }</style>

<rich:dataTable id="gamesTable"> // columns</rich:dataTable>

<rich:jQuery selector="#gamesTable tr:odd" query="addClass('odd-row')" /><rich:jQuery selector="#gamesTable tr:even" query="addClass('even-row')" />

Page 54: RichFaces 4 Webinar - New and Advanced Features

Exadel

Invoking <rich:jQuery> as a regular JavaScript function

<h:graphicImage width="100" value="/images/venice.png" onmouseover="larger(this, {})" onmouseout="normal(this, {})" />

<rich:jQuery name="larger" query="animate({width:'241px'})" /><rich:jQuery name="normal" query="animate({width:'100px'})"/>

with mouse over

Page 55: RichFaces 4 Webinar - New and Advanced Features

Exadel

RichFaces Validation

Page 56: RichFaces 4 Webinar - New and Advanced Features

Exadel

Bean Validation (JSR 303)

JSF 2 has support for Bean Validation (validation done on server)

public class Bean { @Pattern(regexp="...") private String email;}

<h:inputText id="email" value="#{bean.email}"> <a4j:ajax event="blur"/></h:inputText><rich:message for="email"/>

Bean:

JSF page:

Page 57: RichFaces 4 Webinar - New and Advanced Features

Exadel

Client-Validation Based on Bean ValidationValidation is performed on the client. If no client implementation available, validation automatically falls back to standard, server validation

public class Bean { @Pattern(regexp="...") private String email;}

<h:inputText id="email" value="#{bean.email}"> <rich:validator event="blur"/></h:inputText><rich:message for="email"/>

Bean:

JSF page:

Page 58: RichFaces 4 Webinar - New and Advanced Features

Exadel

Cross field validation with <rich:graphValidator>

<rich:graphValidator value="#{bean}" id="crossField"> <h:inputText value="#{bean.password1}"/> <h:inputText value="#{bean.password2}"/> <rich:message for="email" for="crossField"/></rich:graphValidator>

@Size(min=5,max=15)private String password1;@Size(min=5,max=15)private String password2;

@AssertTrue(message="Passwords don't match")public boolean checkPassword() { return password1.equals(password1);}

Page 59: RichFaces 4 Webinar - New and Advanced Features

Exadel

RichFaces Skins

Page 60: RichFaces 4 Webinar - New and Advanced Features

Exadel

Overwriting Skin CSS<style>.rf-p-hdr { // overwrite skin CSS properties or set any other // CSS properties}</style>

<rich:panel id="panel1">... <rich:panel>

Page 61: RichFaces 4 Webinar - New and Advanced Features

Exadel

Overwriting Skin CSS<style>.rf-p-hdr { // overwrite skin CSS properties}.specialHeader { // define custom CSS for specific panel}</style>

<rich:panel id="panel1">... <rich:panel><rich:panel id="panel2" headerClass="specialHeader">... <rich:panel>

Page 62: RichFaces 4 Webinar - New and Advanced Features

Exadel

Skinning Standard JSF Tags and HTML Tags

<h:button style="background-color: '#{richSkin.tableBackgroundColor}'"/>

Apply to each control:

Page 63: RichFaces 4 Webinar - New and Advanced Features

Exadel

Skinning Standard JSF Tags and HTML Tags

<context-param> <param-name> org.richfaces.enableControlSkinning </param-name> <param-value>true</param-value></context-param>

Apply to all standard controls (JSF and HTML):

Page 64: RichFaces 4 Webinar - New and Advanced Features

Exadel

Skinning standard JSF tags and HTML tags only when special CSS class is applied to parent container <context-param> <param-name> org.richfaces.enableControlSkinningClasses </param-name> <param-value>true</param-value></context-param>

<div class="rfs-ctn"> <h:outputText /> <h:inputText /> <h:commandButton /></div>

Page 65: RichFaces 4 Webinar - New and Advanced Features

Exadel

Where can I try the new RichFaces 4?

http://exadel.com/web/portal/richfaces4demo

Page 66: RichFaces 4 Webinar - New and Advanced Features

Exadel

How can we help with RichFaces?

● Web development with RichFaces

● Version 3 to 4 migration

● Performance tune-up

● Custom component

development

● On-site training

Training Days

JSF 1.2, 2 1-2

RichFaces 3, 4 1-2

JSF and RichFaces 2-3

RichFaces 3 to 4 1-2

Page 67: RichFaces 4 Webinar - New and Advanced Features

Exadel

That's it for RichFaces, there is one more thing I want to

show you.

Page 68: RichFaces 4 Webinar - New and Advanced Features

Exadel

Tiggr (gotiggr.com) is a web application for building and sharing interactive web and

mobile HTML prototypes

Page 69: RichFaces 4 Webinar - New and Advanced Features

Exadel

Page 70: RichFaces 4 Webinar - New and Advanced Features

Exadel

blog.exadel.commkblog.exadel.com

@exadel@maxkatz

[email protected]

gotiggr.com