Beruflich Dokumente
Kultur Dokumente
CONTENTS INCLUDE:
Button
JSF Overview
page.xhtml
<h:commandButton value=”press me” action=”#{bean1.login}”/>
JavaServer Faces (JSF) is the “official” component-based
view technology in the Java EE web tier. JSF includes a set
WEB-INF/classes/com/corejsf/SampleBean.java
of predefined UI components, an event-driven programming
@ManagedBean(name=”bean1”)
model, and the ability to add third-party components. JSF @SessionScoped
is designed to be extensible, easy to use, and toolable. This public class SampleBean {
public String login() {
refcard describes JSF 2.0. if (...) return “success”; else return “error”;
}
...
Development Process }
A developer specifies JSF components in JSF pages, The outcomes success and error can be mapped to pages in
combining JSF component tags with HTML and CSS for styling. faces-config.xml. if no mapping is specified, the page
Components are linked with managed beans—Java classes /success.xhtml or /error.xhtml is displayed.
that contain presentation logic and connect to business logic
and persistence backends. Radio Buttons
page.xhtml
servlet container
www.dzone.com
<h:form>
...
</h:form>
</h:body>
</html> JBoss Developer Studio 2.0
These common tasks give you a crash course into using JSF. • Build web apps using rich JSF components
• Choose from 120+ skinnable RichFaces
Text Field
components
page.xhtml
<h:inputText value=”#{bean1.luckyNumber}”>
• Includes Seam, Hibernate, Drools, JBoss
Portal and much more
WEB-INF/classes/com/corejsf/SampleBean.java
@ManagedBean(name=”bean1”)
For more on JBoss and JSF 2.0, goto
@SessionScoped
public class SampleBean {
jboss.org/jbossrichfaces/
public int getLuckyNumber() { ... }
public void setLuckyNumber(int value) { ... }
...
}
page.xhtml
conversion errors/render response
<h:outputStylesheet library=”css” name=”styles.css” target=”head”/>
validation or conversion errors/render response
...
<h:outputText value=”#{msgs.goodbye}!” styleClass=”greeting”>
faces-config.xml
The jsf expression language
<application>
<resource-bundle> An EL expression is a sequence of literal strings and
<base-name>com.corejsf.messages</base-name> expressions of the form base[expr1][expr2]... As in
<var>msgs</var>
</resource-bundle> JavaScript, you can write base.identifier instead of
</application>
base[‘identifier’] or base[“identifier”]. The base is one of
WEB-INF/classes/com/corejsf/messages.properties the names in the table below or a bean name.
goodbye=Goodbye header A Map of HTTP header parameters, containing only the first value
for each name
parameters: userBean.login(‘order page’) f:selectItem Specifies an item for a select one or select many component
- binding, id: Basic attributes
In JSF, EL expressions are enclosed in #{...} to indicate - itemDescription: Description used by tools only
- itemDisabled: false (default) to show the value
deferred evaluation. The expression is stored as a string and - itemLabel: Text shown by the item
evaluated when needed. In contrast, JSP uses immediate - itemValue: Item’s value, which is passed to the server as a
request parameter
evaluation, indicated by ${...} delimiters. - value: Value expression that points to a SelectItem instance
- escape: true (default) if special characters should be converted
2.0: EL expressions can contain JSTL functions to HTML entities
- noSelectionOption 2.0: true if this item is the “no selection
fn:contains(str, substr) fn:substringAfter(str, separator) option”
fn:containsIgnoreCase(str, substr) fn:substringBefore(str, separator)
fn:startsWith(str, substr) fn:replace(str, substr, f:selectItems Specifies items for a select one or select many component
fn:endsWith(str, substr) replacement) - value: Value expression that points to a SelectItem, an array
fn:length(str) fn:toLowerCase(str)
fn:indexOf(str) fn:toUpperCase(str) or Collection, or a Map mapping labels to values.
fn:join(strArray, separator) fn:trim() - var 2.0: Variable name used in value expressions when
fn:split(str, separator) fn:escapeXml() traversing an array or collection of non-SelectItem elements
fn:substring(str, start, pastEnd) - itemLabel 2.0, itemValue 2.0, itemDescription 2.0,
itemDisabled 2.0, itemLabelEscaped 2.0: Item label,
value, description, disabled and escaped flags for each item in
an array or collection of non-SelectItem elements. Use the
JSF Core Tags variable name defined in var.
- noSelectionOption 2.0: Value expression that yields the “no
selection option” item or string that equals the value of the “no
selection option” item
Tag Description/Attributes
f:ajax 2.0 Enables Ajax behavior
f:facet Adds a facet to a component - execute, render: Lists of component IDs for processing in the
- name: the name of this facet “execute” and “render” lifecycle phases
- event: JavaScript event that triggers behavior. Default: click
f:attribute Adds an attribute to a component for buttons and links, change for input components
- name, value: the name and value of the attribute to set - immediate: If true, generated events are broadcast during
“Apply Request Values” phase instead of “Invoke Application”
f:param Constructs a parameter child component
- listener: Method binding of type void (AjaxBehaviorEvent)
- name: An optional name for this parameter component.
- onevent, onerror: JavaScript handlers for events/errors
- value:The value stored in this component.
f:viewParam 2.0 Defines a “view parameter” that can be initialized with a request
f:actionListener Adds an action listener or value change listener to a component
parameter
f:valueChangeListener - type: The name of the listener class
-name, value: the name of the parameter to set
f:propertyAction Adds an action listener to a component that sets a bean property -binding, converter, id, required, value, validator,
Listener 1.2 to a given value valueChangeListener: basic attributes
- target: The bean property to set when the action event occurs
f:metadata 2.0 Holds view parameters. May hold other metadata in the future
- value: The value to set it to
f:validateBean 2.0 Specify validation groups for the Bean Validation Framework
(JSR 303)
h:selectOneListbox Single-select listbox
f:loadBundle Loads a resource bundle, stores properties as a Map
- basename: the resource bundle name
- value: The name of the variable that is bound to the bundle map
h:selectOneRadio Set of radio buttons binding, converter, id, rendered, Basic attributes
styleClass, value
style, title HTML 4.0
h:selectBooleanCheckbox Checkbox
Attributes for h:body and h:form outcome 2.0 (non-command tags) Value expression yielding the navigation outcome
Attribute Description fragment 2.0 (non-command tags) Fragment to be appended to URL. Don’t include
the # separator
binding, id, rendered Basic attributes
actionListener Method expression of type void (ActionEvent)
dir, lang, style, styleClass, target, title HTML 4.0 attributes charset For h:commandLink only—The character
(acceptcharset corresponds encoding of the linked reference
h:form only: accept, acceptcharset, enctype to HTML accept-charset,
styleClass corresponds to image (button tags) For h:commandButton only—A context-relative
HTML class) path to an image displayed in a button. If you
specify this attribute, the HTML input’s type will
onclick, ondblclick, onkeydown, onkeypress, DHTML events be image
onkeyup, onmousedown, onmousemove, onmouseout,
onmouseover immediate A boolean. If false (the default), actions and
action listeners are invoked at the end of the
h:body only: onload, onunload request life cycle; if true, actions and action
listeners are invoked at the beginning of the
h:form only: onblur, onchange, onfocus, life cycle
onreset, onsubmit
type For h:commandButton: The type of the
generated input element: button, submit, or
Attributes forh:inputText , h:inputSecret , reset. The default, unless you specify the image
h:inputTextarea , and h:inputHidden attribute, is submit. For h:commandLink and
h:link: The content type of the linked resource; for
Attribute Description example, text/html, image/gif, or audio/basic
cols For h:inputTextarea only—number of columns value The label displayed by the button or link
immediate Process validation early in the life cycle binding, id, rendered Basic attributes
redisplay For h:inputSecret only—when true, the input field’s accesskey, dir, disabled HTML 4.0
value is redisplayed when the web page is reloaded (h:commandButton only), lang,
readonly, style, styleClass,
required Require input in the component when the form is tabindex, title
submitted
link tags only: charset, coords,
rows For h:inputTextarea only—number of rows hreflang, rel, rev, shape, target
binding, converter, id, rendered, Basic attributes onblur, onclick, ondblclick, DHTML events
required, value, validator, onfocus, onkeydown, onkeypress,
valueChangeListener onkeyup, onmousedown, onmousemove,
accesskey, alt, dir, HTML 4.0 pass-through attributes—alt, maxlength, onmouseout, onmouseover,
disabled, lang, maxlength, and size do not apply to h:inputTextarea. None onmouseup
readonly, size, style, apply to h:inputHidden
styleClasstabindex, title
onblur, onchange, onclick, DHTML events. None apply to h:inputHidden Attributes for h:outputLink
ondblclick, onfocus,
onkeydown, onkeypress, Attribute Description
onkeyup, onmousedown,
onmousemove, onmouseout, accesskey, binding, converter, id, lang, rendered, Basic attributes
onmouseover, onselect value
charset, coords, dir, hreflang, lang, rel, rev, shape, HTML 4.0 border Width of the table’s border
style, styleClass, tabindex, target, title, type
cellpadding Padding around table cells
enabledClass, disabledClass CSS class for enabled/disabled elements— binding, id, rendered, value Basic attributes
h:selectOneRadio and h:selectManyCheckbox
only
dir, lang, style, styleClass, HTML 4.0
title, width
selectedClass 2.0, CSS class for selected/unselected elements—
onclick, ondblclick, DHTML events
unselectedClass 2.0 h:selectManyCheckbox only
onkeydown, onkeypress,
onkeyup, onmousedown,
onmousemove, onmouseout,
layout Specification for how elements are laid
onmouseover, onmouseup
out: lineDirection (horizontal) or
pageDirection (vertical)—h:selectOneRadio
and h:selectManyCheckbox only
accesskey, border, dir, disabled, HTML 4.0—border only for h:selectOneRadio bgcolor Background color for the table
lang, readonly, style, styleClass, and h:selectManyCheckbox, size only for
border Width of the table’s border
size, tabindex, title h:selectOneListbox and h:selectManyListbox.
cellpadding Padding around table cells
onblur, onchange, onclick, DHTML events
ondblclick, onfocus, onkeydown, cellspacing Spacing between table cells
onkeypress, onkeyup, onmousedown,
onmousemove, onmouseout, first index of the first row shown in the table
onmouseover, onmouseup, onselect
frame Specification for sides of the frame surrounding the table
should be drawn; valid values: none, above, below, hsides,
Attributes for h:message and h:messages vsides, lhs, rhs, box, border
globalOnly Instruction to display only global messages—h:messages dir, lang, style, HTML 4.0
only. Default: false styleClass, title, width
layout Specification for message layout: table or list— onclick, ondblclick, DHTML events
h:messages only onkeydown, onkeypress,
onkeyup, onmousedown,
showDetail A boolean that determines whether message details onmousemove, onmouseout,
are shown. Defaults are false for h:messages, true for onmouseover, onmouseup
h:message.
ui:insert If a name is given, insert named content if defined or use the child ui:param Define a parameter to be used in an included file or template
elements otherwise. If no name is given, insert the content of the -name: parameter name
tag invoking the template -value: a value expression (can yield an arbitrary object)
-name: the name of the content
ui:repeat Repeats the enclosed elements
ui:composition Produces content from a template after processing child -value: a List, array, ResultSet, or object
elements (typically ui:define tags) Everything outside the -offset, step, size: starting intex, step size, ending
ui:composition tag is ignored index of the iteration
-template: the template file, relative to the current page -var: variable name to access the current element
-varStatus: variable name to access the iteration
ui:component Like ui:composition, but makes a JSF component status, with integer properties begin, end, index, step
-binding, id: basic attributes and Boolean properties even, odd, first, last
ui:decorate, Like ui:composition, ui:component, but does not ignore the ui:debug Shows debug info when CTRL+SHIFT+a key is pressed
ui:fragment content outside the tag -hotkey: the key to press (default d)
-rendered: true (default) to activate
ui:include Include plain XHTML, or a file with a ui:composition or
ui:component tag ui:remove Do not include the contents (useful for comments or temporarily
-src: the file to include, relative to the current page deactivating a part of a page)
A B O U T t h e Au t h o r REC O MMEN D E D B oo k
Cay S. Horstmann has written many books on C++, Core JavaServer Faces
Java and object-oriented development, is the series delves into all facets of
editor for Core Books at Prentice-Hall and a frequent
JSF development, offering
speaker at computer industry conferences. For four
years, Cay was VP and CTO of an Internet startup that systematic best practices for
went from 3 people in a tiny office to a public company. building robust applications
He is now a computer science professor at San Jose and maximizing developer
State University. He was elected Java Champion in 2005. productivity.
Bro
ugh
t to
you
by...
Professional Cheat Sheets You Can Trust
tt erns “Exactly what busy developers need:
n Pa
ld
ona
sig son
McD
simple, short, and to the point.”
De
Ja
By
#8
ired
Insp e
by th
GoF ller con
tinu
ed
ndle
r doe
sn’t
have
to
in tab
Cha d ultip ecific o should cep pat
this if the m up the
man
n M
an ac
z.co
n
sp s ents
be a ject ime. d is see passed
Download Now
Com reter of ob at runt handle plem ks to de to
...
n
uest som tion proces e no m
Itera tor ore req
n A g in metho
d
cep
dm ndlin
e e ar
tho e to ptio th
Exce ion is sm to ha up th tered or
e ca
n
Ob
se Me S renc ral
Refcardz.com
plate RN refe listed in mp
le ce pt ni
echa n pa ssed co un avio
Beh
TTE
n
ex
is en
ick
Core Java Concurrency Windows Powershell
am
Tem Exa he .
A s has ack. W tion uest to ject
NP a qu s, a ct- cep Ob
it
n
st q
IG e s e rn b je call e ex e re
vid patt able O le th nd th
DES
! V is
pro s, hand s to ha
UT ard ign us ram .
des diag
Java Performance Tuning Dependency Injection with EJB 3
ct
ABO refc oF) f Re le obje
erns ts o lass exa
mp oke
r
Patt ur (G lemen es c Inv
arz
n F o d rl d h
Des
ig go
f s: E inclu al w
o suc
Th is G a n
l 23 sign Pa
tt e rn e rn
patt , and a
re je ts
t ob mentin
c g AN
D
Eclipse RCP Netbeans IDE JavaEditor
c
a h c M M
ef
in c u
orig kD
e
re.
Ea tion ons
tr ple CO ma
nd
boo Softwa rma to c their im om
HTML Getting Started with Eclipse
re R
( low
e x p o n la rg cute is al ch
ati an b rm ts. +exe . Th
bject nship
s su
Cre y c fo je c an o
t th
e
ed
to ob ms, d as ed rela
tio
Get
nsh
ips
that
can psu
Enca quest
the
re
late
sa
and
e ha
to b llbacks
ca
.
nalit
y.
riant
times
or in
varia
ling
the
invo
catio
ing
n.
DZone, Inc. ISBN-13: 978-1-934238-61-5
ra o pose uing nctio led at va hand
io n ti ct cess be
av ,a la P ur
as q
ue
ack
fu je pro
Beh nships t re
1251 NW Maynard
ob
e
ISBN-10: 1-934238-61-9
nd the to
je c a n b callb b e ha eded. m ro nous nality ed
tio ob at c
ed
You ne s need
to ne
sts is couple
d fro
ynch nctio y ne
rela with s th st que
n
e th
e as the fu
itho
ut an is
eals
it
ship Reque y of re de ar
ld be litat pattern ssing w tation articul
e: D tion faci
50795
or
e. Use
n
A hist shou d ce en p
ed to mman for pro implem ents its ting.
cop runtim rela type
ker
Cary, NC 27513
n
S s Whe invo y us
n
s co al m pec
jec t at cla Pro
to Th e
w id el th e ue ue
ac tu
d im
p le ex
are utilizing a job q of the ue is
Ob ged with
n
C ues ueue e que
han eals me.
y dge enq
que s. B en to th
e c : D P roxy Job orithm be giv knowle that is terface
b e ti
cop
g n ct
pile r S in
rato er mp
le of al ed ca to have d obje of the
ss S at com serv
888.678.0399
Exa ut
Deco nes
an
.com
919.678.0300
one
Abst tory
C C
Fac
B
State
t
pte
r eigh y
teg
Ada Flyw Stra od
z
Meth
more than 3.3 million software developers, architects and decision
S S r B
w. d
e rp rete plate
ridg
Refcardz Feedback Welcome
B B
Inte Tem
S B
er tor or
ww
C B r B
NSIB
ILIT
Y B
S
Com
po si te
P O succ
ess
or Sponsorship Opportunities 9 781934 238615
RES
“DZone is a developer’s dream,” says PC Magazine.
F
CH
AIN
O
ace
>> sales@dzone.com
terf r
<<in andle
H st ( )
re
ndle
+ha
ern
1 ki ng
ler by lin .c o
m
and uest one
teH req z
cre () le a w.d
Con uest hand | ww