RichFaces 4.0
CONTENTS INCLUDE:
n
Introduction
n
Getting Started
Core JSF 2 Extensions
A Next Generation JSF Framework
n
n
Render Options
n
Queue
n
Client-Side Validation and more... By Nick Belaevski, Ilya Shailkovsky, Max Katz, and Jay Balunas
For other build systems such as Ant just add the following jars to
INTRODUCTION your projects WEB-INF/lib directory: richfaces-core-api-<ver>.jar,
richfaces-core-impl-<ver>.jar, richfaces-components-api-<ver>.jar,
RichFaces 4.0 is an advanced JSF 2.0 based framework that richfaces-components-ui-<ver>.jar, sac-1.3.jar, cssparser-0.9.5.jar,
provides a complete range of rich Ajax enabled UI components, and google-guava-r08.jar.
as well as other features such as a component development kit,
dynamic resource support, and skinning. The 4.0 version brings
complete JSF 2.0 support to the project. Hot No filters or other updates to your web.xml are
Tip needed to install RichFaces 4.0.
RichFaces is made up of two component tag libraries. “a4j:”
represents core Ajax functionality, and page wide controls. Page Setup
While the “rich:” component set represent self contained and To use RichFaces components in your views add:
advanced UI components such as calendars, and trees.
xmlns:a4j=”http://richfaces.org/a4j”
JavaServer Faces 2.0 xmlns:rich=”http://richfaces.org/rich”
The second version of JSF added many features such as, core Maven Archetypes
Ajax functionality, integrated Facelets support, annotations, The project also contains several Maven archetypes to
view parameters, and more. RichFaces 4.0 has been specifically quickly create projects (including one for Google App Engine
redesigned to not only work with these new features, but to targeted project).
extend them.
Simple project generation:
Hot JSF 2.0 is covered in detail in the DZone JavaServer mvn archetype:generate
-DarchetypeGroupId=org.richfaces.archetypes
Tip Faces 2.0 Refcard. -DarchetypeArtifactId=richfaces-archetype-simpleapp
-DarchetypeVersion=<version> -DgroupId=<yourGroupId>
-DartifactId=<yourArtifactId> -Dversion=<yourVersion>
RichFaces 4.0: A Next Generation JSF Framework
GETTING STARTED From the generated project directory you can build, and deploy
as with any Maven project.
RichFaces can be used in any container that JSF 2.0 is
compatible with. This means all servers compliant with the EE6 Hot Easily import in JBoss Tools using m2eclipse
specification ( JBoss AS6/7, Glassfish 3 ) and all major servlet Tip http://jboss.org/tools.
containers (Tomcat, Jetty).
Hot Check the RichFaces project page for the latest CORE JSF 2 EXTENSIONS
Tip information and downloads: http://richfaces.org
a4j:ajax
Installing RichFaces Upgrades the standard f:ajax tag/behavior with more features.
Since RichFaces is build on top of JSF 2.0 its installation is as
easy as adding a few jars to your project.
For Maven-based projects configure your repositories following
the Maven Getting Started Guide here:
http://community.jboss.org/wiki/MavenGettingStarted-Users
Then simply add the following to you projects pom.xml.
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.richfaces</groupId>
<artifactId>richfaces-bom</artifactId>
<version>${richfaces.version}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
…
<dependency>
<groupId>org.richfaces.ui</groupId>
<artifactId>richfaces-components-ui</artifactId>
</dependency>
<dependency>
<groupId>org.richfaces.core</groupId>
<artifactId>richfaces-core-impl</artifactId>
</dependency>
Similar to standard h:commandButton and h:commandLink tags Server side messages are published and topics are created/
but with Ajax behavior built-in. configured using a class similar to this:
<a4j:commandButton value=”Add” @PostConstruct
action=”#{bean.add}” render=”cities”/> public void init() {
<h:panelGrid id=”cities”>...</h:panelGrid> topicsContext = TopicsContext.lookup();
}
private void say(String message) throws
MessageException {
Hot TopicKey key = new TopicKey(“chat”,”topic”);
Default execute value for both controls is @form. topicsContext.publish(key, message);
Tip }
private void onStart() {
topicsContext.getOrCreateTopic(new
TopicKey(“chat”));
a4j:poll }
Periodically fires an Ajax request based on polling interval For more details on usage and setup, including examples please
defined via interval attribute and can be enabled/disabled via see the RichFaces Component Guide (http://docs.jboss.org/
enabled attribute (true|false). For example, in the following code richfaces/latest_4_0_X/Component_Reference/en-US/html/).
snippet, an Ajax request will be sent every 2 seconds and render
the time component: a4j:param
Works like <f:param> also allows client side parameters and will
<a4j:poll interval=”2000” enabled=”#{bean.active}”
action=”#{bean.count}” render=”time”/>
assign a value automatically to a bean property set in assignTo :
<h:outputText id=”time” value=”#{bean.time}”/>
<a4j:commandButton value=”Select”>
<a4j:param value=”#{rowIndex}”
a4j:jsFunction assignTo=”#{bean.row}”/>
</a4j:commandButton>
Allows the sending of an Ajax request from any JavaScript function.
<a4j:jsFunction name=”setdrink” render=”drink”>
a4j:log
<a4j:param name=”param1” assignTo=”#{bean.drink}”/> Client-side Ajax log and debugging.
</a4j:jsFunction>
...
<td onmouseover=”setdrink(‘Espresso’)” <a4j:log/>
onmouseout=”setdrink(‘’)”>Espresso</td>
<h:outputText id=”drink” value=”I like #{bean.drink}” />
<a4j:region> <context-param>
<a4j:poll interval=”10000”/> <param-name>
<h:inputText value=”#{bean.name}”/> org.richfaces.queue.enabled</param-name>
<h:inputText value=”#{bean.email}”/> <param-value>true</param-value>
</a4j:region> </context-param>
a4j:outputPanel <h:form>
<a4j:queue/>
<a4j:outputPanel ajaxRendered=”true”> is an auto-rendered </h:form>
Limiting Rendering ignoreDupResponses Response processing for requests will not occur if a similar request is
already waiting in the queue, saving the client side processing.
To limit rendering to only components set in current render
list, set limitRender=”true”. In the following example, only There are two ways to set queue options. Directly on
components c1 and c2 will be rendered (a4j:outputPanel update a4j:queue tag:
is turned off):
<a4j:queue name=”ajaxQueue” requestDelay=”3000”/>
(a4j:outputPanel, rich:message(s)).
CLIENT-SIDE VALIDATION
QUEUE
Bean Validation
JSF 2 provides a basic client request queue out-of the box.
Bean Validation (JSR-303) provides a tier agnostic approach to
RichFaces extends the standard JSF queue, and provides
define constraints on model objects. Every tier must then validate
additional features to improve usability.
those constraints. There are a set of built in constraints, defined
The RichFaces queue is defined via the a4j:queue tag. Queues by the Bean Validation specification. JSF 2.0 has built in Bean
can be named or unnamed as described below. Validation support, but only with server side validation.
Named Queue rich:validator
Named queues are given a name and will only be used by RichFaces 4.0 provides true client side validation that
components which reference them directly: seamlessly integrates into JSF 2.0 Bean Validation support.
There is an Ajax server side fallback mechanism if client side
<a4j:queue name=”ajaxQueue”>
<h:form> validation is not possible.
<a4j:commandButton>
<a4j:attachQueue name=”ajaxQueue”/>
</a4j:commandButton> Object constrained using Bean Validation
</h:form>
public class Foo{
Unnamed Queue ...
@NotNull
Unnamed queues are used to avoid having to reference named @Pattern(regexp=”^\d{5}(-\d{4})?$”)
private String zipcode;
queues for every component and come with the following ...
}
scopes: global, view, form.
Global level Client side validation on a specific field
Global queue is available on all the views and defined in <h:inputText id=”input” value=”#{foo.zipcode}>
web.xml file: <rich:validator event=”keyup”>
</h:inputText>
<rich:message for=”input” ..../>
Data Iteration
The client side versions of constraints, converters, and messages
must be implemented for this to work. All standard bean
validation constraints are supported.
New password validation dataScroller paging support for any iteration component
PasswordBean Implementation
public class PasswordBean implements Cloneable {
@Size(min=6) @GoodPassword
private String password ;
@Size(min=6)
private String retypePassword ; Component Description
@AssertTrue(message=”Passwords do not match”) tree Rendering of hierarchical data in a tree control. Built in
public boolean match(){
return password.equals(retypePassword); selection and nodes lazy loading.
}}
treeNode Defines representation for a node of a concrete type.
The password bean is cloned, updated, and validated all in the treeModelAdaptor, Declarative definition of tree data model from various
validation phase, allowing only clean data to move to the update treeModelRecursiveAdaptor data structures.
model phase.
Menus
RICH:* TAGS
fileUpload Asynchronous multiple files upload control. dragIndicator Visualization for dragged element.
Output Misc
Component Description
jQuery Declarative jQuery calls definitions.
Component Description
CLIENT FUNCTIONS
panel, popupPanel, Simple panels with header. Expansion, collapse, modal and
collapsiblePanel non modal popups.
RichFaces provides a number of client-side functions which make
it easy to access elements in the browser.
1. richfaces/latest_4_0_X/Component_Reference/en-US/html/
Now you can run mvn install as usually to build application and
GOOGLE APPLICATION ENGINE SUPPORT use mvn gae:deploy for deployment.
#82
CONTENTS INCLUDE:
■
■
About Cloud Computing
Usage Scenarios Getting Started with
Aldon Cloud#64Computing
■
Underlying Concepts
Cost
by...
■
Upcoming Refcardz
youTechnologies ®
■
Data
t toTier
brough Comply.
borate.
Platform Management and more...
■
Chan
ge. Colla By Daniel Rubio
on:
dz. com
grati s
also minimizes the need to make design changes to support
CON
ABOUT CLOUD COMPUTING one time events. TEN TS
INC
s Inte -Patternvall
■
HTML LUD E:
Basics
Automated growthHTM
ref car
Continuous Delivery
Usef
ContiPatterns an
■
However, the demands and technology used on such servers faced by web applications.Structure Tools
Core
Key ■
Structur Elem
E: has changed substantially in recent years, especially with al Elem ents
INC LUD gration the entrance of service providers like Amazon, Google and Large scale growth scenarios involvingents
specialized
NTS and mor equipment
rdz !
HTML
CO NTE Microsoft. es e... away by
(e.g. load balancers and clusters) are all but abstracted
Continu at Every e chang
About ns to isolat
relying on a cloud computing platform’s technology.
Software i-patter
space
CSS3
■
n
Re fca
e Work
Build
riptio
and Ant These companies Desc have a Privat
are in long deployed trol repos
itory
webmana applications
ge HTM
L BAS
■
Build
re
Repo
This Refcard active
will introduce are within
to you to cloud riente computing, with an
ION d units etc. Some platforms ram support large grapRDBMS deployments.
■
The src
dy Ha
softw
EGRAT ware
Mainl
ine
emphasis onDeve
loping
es by
task-o it and Java s written in hical on of
all attribute
S INT soft these ines providers, so youComm can better understand
also rece JavaScri user interfac web develop and the rris
NoSQL
codel chang desc
INUOU ding Task Level as the
e code
www.dzone.com
Spring Roo
reposit -patter particu s cies Pay only what you consume
tagge or Amazon’s cloud
the curr you
computing cho platform isome heavily basedmoron very little fi ne. b></ ed insid
lained ) and anti x” the are solution duce
nden For each (e.g. WAR es t
ent stan ose to writ more e imp a></ e
not lega each othe
b> is
be exp text to “fi
al Depeapplication deployment
Web ge until
nden a few years
t librari agonmen
t enviro was similar that will software
industry standard and virtualization app
e HTM technology.
ortant,
tterns to pro Minim packa
dard
Mo re
CI can ticular con used can rity all depe all targe
s will L or XHT arent. Reg the HTM l, but r. Tags
es
s. Ant
i-pa
, they
tend but to most
y Integ phone services: alizeplans with le that
fialloted resources, ts with an and XHT simplify all help ardless L VS <a><
etim ctices, XHTM
late
in a par hes som
Binar Centr temp your you prov ML, b></
proces in the end bad pra enting
nt nmen
incurred cost
geme whether e a single based on
Creatsuchareresources were consumed
t enviro orthenot. Virtualization
muchallows MLaare physical othe
piece ofr hardware to be understand of HTML L
approac ed with the cial, but, implem
cy Mana nt targe es to actually web cod ide a solid
essarily of the ing has
nden rties
d to Depe prope into differe chang
utilized by multiple operating simplerThis allows
function systems. ing.resourcesfoundati job adm been arou
ciat efi nec pare er itting
Ge t
builds
asso ben are not
Verifi te e comm commo than
ality be allocated Fortuna on nd for
to be n com expecte irably, that
late
Cloud computing asRun it’sremo
known etoday beforhas changed this.
They they
etc.
(e.g. bandwidth, elem CPU) tohas
nmemory, exclusively totely
Temp
job has some time
Build
lts whe
ually,
appear effects. rm a
Privat y, contin nt team Every mov
entsinstances. ed to CSS
used
to be, HTML d. Earl
ed resu gration
The various resourcesPerfo consumed by webperio applications
dicall (e.g.
opme pag
individual operating system because Brow
ser man y HTML expand . Whi
adverse unintend d Builds sitory Build r to devel common e (HTML . le it has
ous Inte ed far
Stage Repo
e bandwidth, memory, CPU) areIntegtallied
ration on a per-unit CI serve basis or XHT web dev ufac had very done
produc Continu Refcard
e Build rm an ack from extensio .) All are elopers turers add
more
e.com
the not
s on
DZone, Inc.
expand
tutorials, cheat sheets, blogs, feature articles, source code and more.
refcardz@dzone.com
“DZone is a developer’s dream,” says PC Magazine.
Sponsorship Opportunities
Copyright © 2010 DZone, Inc. All rights reserved. No part of this publication may be reproduced, stored in a
retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, sales@dzone.com Version 1.0
without prior written permission of the publisher.