Vous êtes sur la page 1sur 59

!

Sl: an lnLroducuon
8ased on verslon 2.2
!Sl archlLecLure
1he conLalner
1o use !Sl a bare 1omcaL ls noL enough: you
need a !Sl appllcauon server (e.g. Classsh).

1omcaL can be congured Lo run !Sl:
See hup://www.byLeslounge.com/LuLorlals/
how-Lo-congure-[sf-ln-LomcaL-example
1he llfecycle
lnLeracuon beLween Lhe page and Lhe
beans
varlables ln Lhe bean can be accessed Lhrough
Lhe Lxpresslon Language

$[myCb[.myvar}

Accesses Lhe myvar varlable ln Lhe myCb[ bean
lL was already avallable ln !S



Java Standard Template Library
JSTL
hup://[ava.sun.com/producLs/[sp/LuLorlal/1agLlbrarles1CC.hLml
!S1L
Core Lags

<%@ taglib
uri="http://java.sun.com/jsp/jstl/core"
prefix="c" %>
See http://download.oracle.com/javaee/5/tutorial/doc/bnakh.html
<c:set var="foo" scope="session" value="..."/>

${foo}
!S1L - xml
xML Lags

<%@ taglib
uri="http://java.sun.com/jsp/jstl/xml"
prefix="x" %>
See http://download.oracle.com/javaee/5/tutorial/doc/bnakq.html
<c:if test="${applicationScope:booklist == null}" >
<c:import url="${initParam.booksURL}" var="xml" />
<x:parse doc="${xml}" var="booklist" scope="application" />
</c:if>
<x:set var="abook"
select="$applicationScope.booklist/books/book[@id=$param:bookId]" />
<h2><x:out select="$abook/title"/></h2>
!S1L - sql
SCL Lags

<%@ taglib
uri="http://java.sun.com/jsp/jstl/sql"
prefix="sql" %>
See http://download.oracle.com/javaee/5/tutorial/doc/bnald.html
<sql:setDataSource dataSource="jdbc/BookDB" />
<c:set var="bid" value="${param.Add}"/>
<sql:query var="books" >
select * from PUBLIC.books where id = ?
<sql:param value="${bid}" />
</sql:query>
!S1L-fn
funcuon Lags

<%@ taglib
uri="http://java.sun.com/jsp/jstl/functions"
prefix="fn" %>
See http://download.oracle.com/javaee/5/tutorial/doc/bnalg.html

<c:if test="${fn:length(param.username) > 0}" >
<%@include file="response.jsp" %>
</c:if>

!S1L-fmL
l18n Lags

<%@ taglib
uri="http://java.sun.com/jsp/jstl/fmt"
prefix="fmt" %>
See http://download.oracle.com/javaee/5/tutorial/doc/bnakw.html

<h3><fmt:message key="Choose"/></h3>




JSF Tags
!Sl llbrarles/Lags
P1ML Lags
hup://docs.oracle.com/[avaee/7/LuLorlal/doc/[sf-
page002.hLm
!Sl Core 1ag Llbrary
hup://docs.oracle.com/[avaee/7/LuLorlal/doc/[sf-
page003.hLm
ComposlLe 1ag Llbrary
hup://docs.oracle.com/[avaee/7/LuLorlal/doc/[sf-
faceleLs003.hLm

!Sl P1ML 1ag Llbrary
ConLalns !avaServer laces componenL Lags for all
ulComponenL + P1ML 8enderklL 8enderer
comblnauons dened ln Lhe !Sl Speclcauon.
h:head h:body
h:form h:lnpuL1exL
h:daLa1able

hup://www.[soolbox.com/documenLauon/help/
12-1ag8eference/hLml/lndex.[sf
WldgeLs
<h:lnpuL1exL>
<h:lnpuLSecreL>
<h:lnpuL1exLarea>
<h:lnpuLPldden>
<h:selecL8ooleanCheckbox>
<h:selecLManyCheckbox >
<h:selecLCne8adlo>
<h:selecLCneLlsLbox>
<h:selecLManyLlsLbox>
<h:selecLCneMenu>
<h:selecLManyMenu >
<h:ouLpuL1exL> Lag.
<h:ouLpuLlormaL>
<h:graphlclmage>
<h:ouLpuLSLylesheeL>
<h:ouLpuLScrlpL>
<h:buuon> and <h:command8uuon>
<h:llnk>, <h:commandLlnk> <h:ouLpuLLlnk>
<h:panelCrld>
<h:messages> and <h:message>
<f:param>
<f:aurlbuLe>
<f:seLproperLyacuonllsLener>
lor examples see
hup://www.mkyong.com/LuLorlals/[sf-2-0-LuLorlals/
!Sl Core 1ag Llbrary

conLalns general purpose Lags for converslon,
valldauon, A[ax, and oLher use cases.

See hup://www.[soolbox.com/
documenLauon/help/12-1ag8eference/core/
lndex.[sf
ComposlLe 1ag Llbrary

1he composlLe Lag llbrary supporLs Lhe
denluon and lmplemenLauon of composlLe ul
componenLs based on Lhe laceleLs vlew
declarauon language (vuL).
ComposlLe LuLorlals
hups://weblogs.[ava.neL/blog/drlscoll/
archlve/2008/11/wrlung_a_slmpl.hLml

hup://www.llferay.com/lL/web/nell.grlmn/
blog/-/blogs/[sf-2-0-LesL-drlve-parL-13A-
developlng-a-faceleL-composlLe-componenL
LxLra llbrarles
8lchlaces (hup://www.[boss.org/rlchfaces)
rlmelaces (hup://www.prlmefaces.org/)
lCLlaces (hup://www.lceso.org/[ava/home.[sf)
1rlnldad(hup://myfaces.apache.org/Lrlnldad/)
1omahawk (hup://myfaces.apache.org/
Lomahawk/)
An example
An example: hello bean
package helloackage,
lmporL [avax.enLerprlse.conLexL.8equesLScoped,
lmporL [avax.ln[ecL.named,
[named
[8equesLScoped
publlc class Pello [
prlvaLe SLrlng name,
publlc Pello() [ }
publlc SLrlng geLname() [
reLurn name,
}
publlc vold seLname(SLrlng user_name) [
Lhls.name = user_name,
}
}

1he bean wlll be called
hello"
An example: lndex.xhLml
<?xml verslon='1.0' encodlng='u1l-8' ?>
<!uCC1?L hLml u8LlC "-//W3C//u1u xP1ML 1.0 1ransluonal//Ln" "hup://www.w3.org/18/xhLml1/u1u/xhLml1-Lransluonal.dLd">
<hLml lang="en" xmlns="hup://www.w3.org/1999/xhLml" xmlns:h="hup://xmlns.[cp.org/[sf/hLml">
<h:head>
<uLle>laceleLs Pello Creeung</uLle>
</h:head>
<h:body>
<h:form>
<h:graphlclmage url="#[resource['lmages:duke.wavlng.glf']}" alL="uuke wavlng hls hand"/>
<h2>Pello, my name ls uuke. WhaL's yours?</h2>
<h:lnpuL1exL ld="username"
uLle="My name ls: "
value="#{he||o.name}"
requlred="Lrue"
requlredMessage="Lrror: A name ls requlred."
maxlengLh="23" />
<p></p>
<h:command8uuon ld="submlL" value="SubmlL" acuon="response"> </h:command8uuon>
<h:command8uuon ld="reseL" value="8eseL" Lype="reseL"> </h:command8uuon>
</h:form>
...
</h:body>
</hLml>


An example: response.xhLml
<?xml verslon='1.0' encodlng='u1l-8' ?>
<!uCC1?L hLml u8LlC "-//W3C//u1u xP1ML 1.0 1ransluonal//Ln"
"hup://www.w3.org/18/xhLml1/u1u/xhLml1-Lransluonal.dLd">
<hLml lang="en"
xmlns="hup://www.w3.org/1999/xhLml"
xmlns:h="hup://xmlns.[cp.org/[sf/hLml">
<h:head>
<uLle>laceleLs Pello 8esponse</uLle>
</h:head>
<h:body>
<h:form>
<h:graphlclmage url="#[resource['lmages:duke.wavlng.glf']}"
alL="uuke wavlng hls hand"/>
<h2>Pello, #{he||o.name}!</h2>
<p></p>
<h:command8uuon ld="back" value="8ack" acuon="lndex" />
</h:form>
</h:body>
</hLml>

An example: web.xml
<?xm| vers|on="1.0" encod|ng="U1I-8"?>
<web-app vers|on="3.1" xm|ns="hup:]]xm|ns.[cp.org]xm|]ns][avaee" xm|ns:xs|="hup:]]www.w3.org]2001]kMLSchema-|nstance"
xs|:schemaLocanon="hup:]]xm|ns.[cp.org]xm|]ns][avaee hup:]]xm|ns.[cp.org]xm|]ns][avaee]web-app_3_1.xsd">
<context-param>
<param-name>[avax.faces.kCILC1_S1AGL<]param-name>
<param-va|ue>Deve|opment<]param-va|ue>
<]context-param>
<serv|et>
<serv|et-name>Iaces Serv|et<]serv|et-name>
<serv|et-c|ass>[avax.faces.webapp.IacesServ|et<]serv|et-c|ass>
<|oad-on-startup>1<]|oad-on-startup>
<]serv|et>
<serv|et-mapp|ng>
<serv|et-name>Iaces Serv|et<]serv|et-name>
<ur|-pauern>]faces]*<]ur|-pauern> Ck <ur|-pauern>*.faces<]ur|-pauern>
<]serv|et-mapp|ng>
<sess|on-conhg>
<sess|on-nmeout> 30 <]sess|on-nmeout>
<]sess|on-conhg>
<we|come-h|e-||st>
<we|come-h|e>faces]|ndex.xhtm|<]we|come-h|e>
<]we|come-h|e-||st>
<]web-app>
An example: beans.xml
<?xm| vers|on="1.0" encod|ng="U1I-8"?>
<beans xm|ns="hup:]]xm|ns.[cp.org]xm|]ns][avaee"
xm|ns:xs|="hup:]]www.w3.org]2001]kMLSchema-|nstance"
xs|:schemaLocanon="hup:]]xm|ns.[cp.org]xm|]ns][avaee hup:]]xm|ns.[cp.org]xm|]ns][avaee]
beans_1_1.xsd"
bean-d|scovery-mode="annotated">
<]beans>
1he presence of a beans.xml le slgnals Lhe servleL conLalner LhaL Lhe appllcauon uses !S8-299
(ConLexLs and uependency ln[ecuon) - wlLhouL lL, Lhe appllcauon's classes wlll noL be scanned
for Cul annoLauons elLher and dependency ln[ecuon wlll noL be performed.
lf you don'L use Cul (e.g. you only use plaln !Sl managed beans), you don'L need beans.xml.
lnner worklng
All !Sl pages are processes by a speclal servleL
(lacesServleL) LhaL ls a parL of Lhe !Sl
lmplemenLauon code.
1he !Sl u8Ls have a speclal formaL Lo ensure LhaL
Lhe correcL servleL ls acuvaLed when a !Sl page ls
requesLed.
lor example, Lhey may have an exLenslon .faces.
Lx: hup://localhosL:8080/hello/lndex.faces.
Cr, you can also dene a prex mapplng lnsLead of
Lhe .faces exLenslon mapplng.

(managed or Cul) beans
unul !Sl 2.0 Lhe use of Managed8eans was Lhe way Lo go

[Managed8ean
publlc class Somename [ . }

lrom !Sl 2.2 one uses Cul beans

use of [Managed8ean from [avax.faces.bean ls now deprecaLed,
lnsLead one should use [named from [avax.ln[ecL package Lo slgnlfy
a managed bean as a !Sl conLroller class.
lf you do, you can use Lhe le (lnsLead of annoLauons) Lo dene Cul
congurauons - Lhls allows you, for example, Lo provlde a LesL
congurauon where some dependencles are replaced wlLh mocks.
8ean scope
AppllcauonScoped - only one lnsLance of Lhe bean wlll exlsL ln Lhe enure
appllcauon. Aer bean lnluallzauon, every ume a cllenL requesLs an lnsLance of
Lhls bean Lhe conLalner wlll always provlde Lhe same bean lnsLance.
SesslonScoped - used lnslde a web appllcauon conLexL. An lnsLance of Lhls bean
wlll exlsL per P11 sesslon.
8equesLScoped - used lnslde a web appllcauon conLexL. An lnsLance of Lhls bean
wlll exlsL per P11 requesL.
ConversauonScoped - used lnslde a web appllcauon conLexL. 1hls klnd of beans are
used Lo represenL a conversauon beLween Lhe cllenL and Lhe server. 1hey may be
used Lo keep sLaLe beLween muluple cllenL A!Ax requesLs or even beLween dlsuncL
page requesLs, lf Lhe cllenL provldes Lhe conversauon ldenuer Lo Lhe server
beLween page requesLs.

Dependent scope ls Lhe defaulL Cul bean scope, le. lf a bean does noL declare a
speclc scope lL wlll be ln[ecLed as a uependenL scoped bean. 1hls means LhaL lL
wlll have Lhe same scope as Lhe bean where lL's belng ln[ecLed. uependenL scoped
bean lnsLances are never shared beLween cllenLs. Lvery cllenL wlll always feLch a
new lnsLance of a uependenL scoped bean.
Conversauonal scope vs. sesslon
Conversauonal scope ls programmaucaly dellmlLed.
prlvaLe [ln[ecL Conversauon conversauon,
conversauon.begln(),
conversauon.end(),
lor examples, see:
hup://sLackoverow.com/quesuons/778830/
how-does-[sf-2-conversauonscope-work
hup://www.byLeslounge.com/LuLorlals/[ava-ee-
cdl-conversauonscoped-example
vlew scope?
no more vlew scope ln !Sl 2.2. 8eplace lL wlLh
Lhe conversauonal scope.

Managed Cul beans LhaL are able Lo llve for
longer perlods of ume, such as SesslonScoped
and ConversauonScoped, musL lmplemenL Lhe
Serlallzable lnLerface.
!Sl: Lxpresslon Language
8ased on verslon 2.2
Lxpresslon language
<some:Lag>
some LexL #[expr} some LexL
</some:Lag>
<anoLher:Lag value="#[expr}"/>
<h:command8uuon ld="submlL"
acuon="#[cusLomer.submlL}" />
<h:command8uuon ld="submlL"
acuon="#[cusLomer["submlL"]}" />
<h:lnpuL1exL value="#[usernumber8ean.usernumber('3')}">
<h:command8uuon acuon="#[Lrader.buy('SCMLS1CCk')}"
value="buy"/>

Lxpresslon language
#[} are for deferred expresslons (deferred
expresslons are resolved dependlng on Lhe
llfecycle of Lhe page) and can be used Lo read or
wrlLe from or Lo a bean or Lo make a meLhod
call.

$[} are expresslons for lmmedlaLe resoluuon, as
soon as Lhey are encounLered Lhey are resolved.
1hey are read-only.
Lxpresslon language
#[aurlbuLename[enLryname]}
Works for
- llelds. LqulvalenL Lo
aurlbuLename.geLLnLryname() (geL or seL)

- Array. LqulvalenL Lo
LheArray[lndex] (geng and seng)

- LlsL. LqulvalenL Lo
LheLlsL.geL(lndex) or LheLlsL.seL(lndex, submlued-val)

- Map. LqulvalenL Lo
LheMap.geL(key) or LheMap.puL(key, submlued-val)

Ca|||ng Methods
<h:lnpuL1exL value="#[usernumber8ean.usernumber('3')}">
Lxpresslon Language - lmpllclL Cb[ecLs
facesConLexL. 1he lacesConLexL ob[ecL.
- L.g. #[facesConLexL.exLernalConLexL.sesslon.ld}

param and paramvalues. 8equesL params.
- L.g. #[param.cusLlu}
header and headervalues. 8equesL headers.
- L.g. #[header.AccepL} or #[header["AccepL"]}
- #[header["AccepL-Lncodlng"]}
cookle. Cookle ob[ecL (noL cookle value).
- L.g. #[cookle.userCookle.value} or
#[cookle["userCookle"].value}
lnlLaram. ConLexL lnluallzauon param.
requesLScope, sesslonScope, appllcauonScope.
Lxpresslon Language - CperaLors
ArlLhmeuc + - / dlv mod
8elauonal == eq != ne < lL > gL <= le >= ge
Loglcal and or ! noL
LmpLy LmpLy
- 1rue for null, empLy sLrlng, empLy array, empLy llsL, empLy map. lalse oLherwlse.

$[ LesL ? expresslon1 : expresslon2 }
CAu1lCn
use exLremely sparlngly Lo preserve MvC model
!Sl: navlgauon
8ased on verslon 2.2
navlgauon
neLbeans: ln Web-lnf, new.CLher, !ava Server laces, !Sl congurauon
1. 1he navlgauonPandler selecLs Lhe navlgauon rule LhaL maLches Lhe page
currenLly dlsplayed.
2. lL maLches Lhe ouLcome or Lhe acuon meLhod reference LhaL lL recelved from Lhe
defaulL [avax.faces.evenL.AcuonLlsLener wlLh Lhose dened by Lhe navlgauon
cases.
3. lL Lrles Lo maLch boLh Lhe meLhod reference and Lhe ouLcome agalnsL Lhe same
navlgauon case.
. lf Lhe prevlous sLep falls, Lhe navlgauon handler auempLs Lo maLch Lhe ouLcome.
3. llnally, Lhe navlgauon handler auempLs Lo maLch Lhe acuon meLhod reference lf
Lhe prevlous Lwo auempLs falled.
. lf no navlgauon case ls maLched, lL dlsplays Lhe same vlew agaln.

hup://docs.oracle.com/[avaee/7/LuLorlal/doc/[sf-lnLro003.hLm#8nACL
hup://sqlLech.cl/doc/oas10g83/web.1013/b2338/web_agenavlgauon002.hLm

Pello.bean
package helloackage,
lmporL [avax.enLerprlse.conLexL.8equesLScoped,
lmporL [avax.ln[ecL.named,
[named
[8equesLScoped
publlc class Pello [
prlvaLe SLrlng name,
publlc Pello() [}
publlc SLrlng geLname() [
reLurn name,
}
publlc vold seLname(SLrlng user_name) [
Lhls.name = user_name,
}
publlc SLrlng readname() [
reLurn name,
}
}
laces.cong.xml
<?xml verslon='1.0' encodlng='u1l-8'?>
<faces-cong verslon="2.2"
xmlns="hup://xmlns.[cp.org/xml/ns/[avaee"
xmlns:xsl="hup://www.w3.org/2001/xMLSchema-lnsLance"
xsl:schemaLocauon="hup://xmlns.[cp.org/xml/ns/[avaee hup://xmlns.[cp.org/xml/ns/[avaee/web-
facescong_2_2.xsd">
<navlgauon-rule>
<from-vlew-ld>/lndex.xhLml</from-vlew-ld>
<navlgauon-case>
<from-ouLcome>plppo</from-ouLcome>
<Lo-vlew-ld>/response.xhLml</Lo-vlew-ld>
</navlgauon-case>
<navlgauon-case>
<Lo-vlew-ld>unknown.xhLml</Lo-vlew-ld>
</navlgauon-case>
</navlgauon-rule>
</faces-cong>
An example: lndex.xhLml
<?xml verslon='1.0' encodlng='u1l-8' ?>
<!uCC1?L hLml u8LlC "-//W3C//u1u xP1ML 1.0 1ransluonal//Ln" "hup://www.w3.org/18/xhLml1/u1u/xhLml1-Lransluonal.dLd">
<hLml lang="en" xmlns="hup://www.w3.org/1999/xhLml" xmlns:h="hup://xmlns.[cp.org/[sf/hLml">
<h:head>
<uLle>laceleLs Pello Creeung</uLle>
</h:head>
<h:body>
<h:form>
<h:graphlclmage url="#[resource['lmages:duke.wavlng.glf']}" alL="uuke wavlng hls hand"/>
<h2>Pello, my name ls uuke. WhaL's yours?</h2>
<h:lnpuL1exL ld="username"
uLle="My name ls: "
value="#[hello.name}"
requlred="Lrue"
requlredMessage="Lrror: A name ls requlred."
maxlengLh="23" />
<p></p>
<h:command8uuon ld="submlL" value="SubmlL" acuon="#{he||o.readName}"> </h:command8uuon>
<h:command8uuon ld="reseL" value="8eseL" Lype="reseL"> </h:command8uuon>
</h:form>
...
</h:body>
</hLml>


unknown.xhLml
<?xml verslon='1.0' encodlng='u1l-8' ?>
<!uCC1?L hLml u8LlC "-//W3C//u1u xP1ML 1.0 1ransluonal//Ln"
"hup://www.w3.org/18/xhLml1/u1u/xhLml1-Lransluonal.dLd">
<hLml lang="en"
xmlns="hup://www.w3.org/1999/xhLml"
xmlns:h="hup://xmlns.[cp.org/[sf/hLml">
<h:head>
<uLle>laceleLs Pello 8esponse</uLle>
</h:head>
<h:body>
<h:form>
<h2>#[hello["name"]}? l do noL know any #[hello["name"]}!</h2>
<p></p>
<h:command8uuon ld="back" value="8ack" acuon="lndex" />
</h:form>
</h:body>
</hLml>
!Sl: valldauon
8ased on verslon 2.2
ueclarauve valldaLor Lags

valldaLe8ean 8eglsLers a bean valldaLor for Lhe componenL.

valldaLeuouble8ange Checks wheLher Lhe local value of a componenL ls wlLhln
a cerLaln range. 1he value musL be oaung-polnL or converuble Lo oaung-polnL.

valldaLeLengLh Checks wheLher Lhe lengLh of a componenLs local value ls
wlLhln a cerLaln range. 1he value musL be a [ava.lang.SLrlng.

valldaLeLong8ange Checks wheLher Lhe local value of a componenL ls wlLhln a
cerLaln range. 1he value musL be any numerlc Lype or SLrlng LhaL can be converLed
Lo a long.

valldaLe8egLx Checks wheLher Lhe local value of a componenL ls a maLch
agalnsL a regular expresslon from Lhe [ava.uul.regex package.

valldaLe8equlred Lnsures LhaL Lhe local value ls noL empLy on an
[avax.faces.componenL.LdlLablevaluePolder componenL.
ueclarauve valldaLor Lags - examples
<h:ouLpuLLabel for="fname"
value="LnLer llrsL name: " uLle="llrsL name"/>
<h:lnpuL1exL ld="fname"
value="#[personvlew.per.fname}" uLle="llrsL name"
requlred="Lrue"
requlredMessage="rsL name ls requlred"/>
<h:message ld="m1" for="fname" sLyle="color:red"/>
ueclarauve valldaLor Lags - examples
<h:ouLpuLLabel for="ranklngld" value="LnLer 8anklng: "
uLle="8anklng"/>
<h:lnpuL1exL ld="ranklngld" value="#[personvlew.ranklng}"
uLle="8anklng"slze="3" valldaLorMessage="8eglsLrauon
Cpen Cnly for Level 3.0 Lo .3">
<f:valldaLeuouble8ange mlnlmum="3.0" maxlmum=".3"
for="ranklngld"/>
<!--f:valldaLe8egex pauern="[3-].?[03]" for="ranklngld"/-->
</h:lnpuL1exL>
<h:message ld="m" for="ranklngld" sLyle="color:red"/>
rogrammauc valldauon - Lhe class
[lacesvalldaLor("emallvalldaLor")
publlc class LmallvalldaLor lmplemenLs valldaLor [
[Cverrlde
publlc vold valldaLe(lacesConLexL conLexL, ulComponenL componenL, Cb[ecL value)
Lhrows valldaLorLxcepuon [
boolean maLches = check(value.LoSLrlng()),
lf (!maLches) [
lacesMessage msg =
new lacesMessage(" L-mall valldauon falled.",
"lease provlde L-mall address ln Lhls formaL: abcd[abc.com"),
msg.seLSeverlLy(lacesMessage.SLvL8l1?_L88C8),
Lhrow new valldaLorLxcepuon(msg),
}
}
prlvaLe boolean check(SLrlng s) [.}
}
rogrammauc valldauon - lnvokauon
<h:ouLpuLLabel for="emall" value="LnLer Lmall: "
uLle="rlmary Lmall"/>
<h:lnpuL1exL ld="emall" value="#[person.emall}"
requlred="Lrue" requlredMessage="emall ls
requlred"
uLle="rlmary Lmall" Lablndex="3">
<f:valldaLor valldaLorld="emallvalldaLor" />
</h:lnpuL1exL>
<h:message ld="m2a" for="emall" sLyle="color:red"/>
rogrammauc valldauon - Lhe class
[named
publlc class erson lmplemenLs valldaLor [
.
publlc vold anyname(lacesConLexL conLexL, ulComponenL
componenL, Cb[ecL value) Lhrows valldaLorLxcepuon [
boolean maLches = check(value.LoSLrlng()),
lf (!maLches) [
.
Lhrow new valldaLorLxcepuon(msg),
}
}
}
rogrammauc valldauon - lnvokauon
<h:ouLpuLLabel for="emall" value="LnLer Lmall: "
uLle="rlmary Lmall"/>
<h:lnpuL1exL ld="emall" value="#[person.emall}"
requlred="Lrue" requlredMessage="emall ls
requlred"
uLle="rlmary Lmall" Lablndex="3"
valldaLor ="person.anyname" />
</h:lnpuL1exL>
<h:message ld="m2a" for="emall" sLyle="color:red"/>
valldauon rules
1. lf form valldauon falls, Lell user LhaL Lhe form valldauon
falled and llsL all Lhe lnsLrucuons/errors aL Lhe Lop of
form.
2. 8epeaL Lhe lnsLrucuons ln fronL/aer Lhe eld.
3. lf posslble seL focus on Lhe "Lop" error message or on Lhe
eld correspondlng Lo Lhe rsL error message.
. use correcL fonL color and slze for dlsplaylng error.
3. 1he error message should Lell Lhe user whaL needs Lo be
done and nC1 whaL ls wrong.
. use correcL Lab lndex or make sure LhaL form elds are ln
a loglcal Lab order
7. When form conLrols are LexL lnpuL elds use Lhe LA8LL
elemenL.
valldaLors
hup://lncepuechnologles.blogspoL.lL/p/
valldauon-ln-[sf.hLml
hup://www.LuLorlalspolnL.com/[sf/
[sf_valldauon_Lags.hLm
!Sl: A[ax supporL
8ased on verslon 2.2
A[ax supporL
A[ax supporL
package pckg,
|mport [ava.un|.*,
|mport [avax.|n[ect.Named,
|mport [avax.enterpr|se.context.kequestScoped,

QNamed(va|ue = "nme8ean")
QkequestScoped
pub||c c|ass A[ax1|me8ean {
Ca|endar x,
pub||c A[ax1|me8ean() {}
pub||c Str|ng nme() {
x=new Gregor|anCa|endar(),
Date d=x.get1|me(),
return d.toStr|ng(),
}
}

lndex.xhLml
<?xml verslon='1.0' encodlng='u1l-8' ?>
<!uCC1?L hLml u8LlC "-//W3C//u1u xP1ML 1.0 1ransluonal//Ln"
"hup://www.w3.org/18/xhLml1/u1u/xhLml1-Lransluonal.dLd">
<hLml lang="en" xmlns="hup://www.w3.org/1999/xhLml"
xmlns:f="hup://[ava.sun.com/[sf/core" xmlns:h="hup://xmlns.[cp.org/[sf/hLml">
<h:head>
<h:outputScr|pt name="[sf.[s" ||brary="[avax.faces" target="head" ]>
<uLle>A!Ax uemo</uLle>
</h:head>
<h:body>
<h2>1lme aL page loadlng ls: #[ume8ean.ume()}</h2>
<h:form>
<h2>LasL reload ume ls: <h:output1ext va|ue="#{nme8ean.nme()}" |d="nmekesu|t"]></h2>
<h:command8uuon ld="submlL" value="updaLe 1lme" acuon="noLhlng">
<f:a[ax render="nmekesu|t"]>
</h:command8uuon>
</h:form>
</h:body>
</hLml>
!Sl: LvenLs
8ased on verslon 2.2
1he llfecycle
LvenLs
name of Lhe evenL for whlch Lo lnsLall a llsLener. 1he followlng Lable llsLs Lhe valld values for Lhls
aurlbuLe, and Lhe correspondlng evenL Lype for whlch Lhe llsLener acuon ls reglsLered.

va|ue for "type" tag aur|bute 1ype of event sent to ||stener method
pre8enderComponenL [avax.faces.evenL.re8enderComponenLLvenL
pre8endervlew [avax.faces.evenL.re8endervlewLvenL
posLAdd1ovlew [avax.faces.evenL.osLAdd1ovlewLvenL
prevalldaLe [avax.faces.evenL.revalldaLeLvenL
posLvalldaLe [avax.faces.evenL.osLvalldaLeLvenL

ln addluon Lo Lhese values, Lhe fully qualled class name of any [ava class LhaL exLends
[avax.faces.evenL.ComponenLSysLemLvenL may be used as Lhe value of Lhe "Lype" aurlbuLe.

So , beslde Lhe values llsLed above , you can also use Lhe fully qualled class name of dlrecL known
subclasses of [avax.faces.evenL.ComponenLSysLemLvenL

hups://[avaserverfaces.[ava.neL/nonav/docs/2.1/[avadocs/[avax/faces/evenL/
ComponenLSysLemLvenL.hLml
hup://www.LuLorlalspolnL.com/[sf/[sf_evenL_handllng.hLm

Vous aimerez peut-être aussi