Professional Documents
Culture Documents
+*-#$"*-$
DA"76(:DF?BD?DBCE
P SQRV '"*-&. *!/2- .D - $)( )/*. -1$:*.
/F **. *. $- $/*.
- . -1*.F
)#0( +-/ ./ '$1-* +* . - - +-*05$ *0 /-).($/$ ( ,0',0 - !*-(D
. % +*- ( $* ' /-?)$* *0 ( 8)$*D . ( + -($..9* +*- .-$/* '"*-&.D
3 /*+-- .0(*.- 1 . (- 1$.@ . )7'$. .F
'"*-&.*!/2- .D- $)( )/*. -1$:*.
/
222F'"2*-&.F*(
*)//*O'"2*-&.F*(
[VVLRRMSWSWGZURV
$"G)*.).- ..*$$. B,0 +*- )/-* /0*H
www.algaworks.com 3
*- *0/*-
#$"*-$ )-
#//+.EJJ222F'$)& $)F*(J$)J/#$"*!
0)*-D $)./-0/*- *).0'/*- '"*-&.F
-0* ( $./ (.
)!*-(:9* -/$B*
*(* +-*"-(*- 1 + ' 0)F
)$$*0 . 0 $)/ - ..
+*- +-*"-(:9* ( RZZVD ,0)* . )1*'1 0 0(
.*!/2- +- )/- / )$( )/* . /*-)*0 0( *. ($.
+*+0'- . )* -.$' *0/-*. +=. . '=)"0 +*-/0"0 .F 7 !*$ .>$* /-'#*0 (
*0/-. (+- .. .*!/2- *(* +-*"-(*-D " - )/ $- /*- / )*'*"$D (.
)0) $3*0 +-*"-(-F
www.algaworks.com 5
)/ . *( :-FFF
)/ . ,0 1*< *( ' - .. '$1-*D 0 "*./-$ *($)- '"0(. *$.. *(
1*<D+-,0 / )#0( 3 ' )/ +-*1 $/( )/***)/ A*F(*.'7I
,0 1*<+- $.. -I
*< .> *). "0$-7 .*-1 - * *)/ A* .. '$1-* . %7 *)# - 1 -$ )/:9*
% /*.F .* $) )9* *)# :D - *( )* ,0 ./0 .*- .. ..0)/* +*-
'"0(*(0-.* *0'$1-*F
*(**/ -%0I
0-)/ *. . 0. ./0*.D 0 / )#* -/ 5 0( *$.E 1*< 1$ / - (0$/. A1$.
+-*' (.+-- .*'1 -H
0 "*./-$ (0$/* / %0- + ..*'( )/ ) .. . +-*' (. .)- /*. . .0.
A1$.D (. $)! '$5( )/ )9* *).$"* !5 - $..* *( /**. *. ' $/*- . * '$1-*D B)'D
0 %7 *0+* "-) +-/ * ( 0 $ %0)* *. ( 0. '0)*. 0-.*. *)'$) )
'"*-&.FFF
. 0 /$1 0( $ $H 0 /' *. ' $/*- . . %0- ( /-1;. 0( .$/ + -"0)/.
- .+*./.I
(*.0.-D*B$'( )/ D* /&1 -C*2 (+*-/0"0<.H.> ..-E
#//+EJJ+/F./&*1 -C*2F*(J
(+- ,0 .0-"$- '"0( A1$D +*./ '7 )* .$/ * /&1 -C*2 ""(' -
@% 0(+$,@F ..!*-(B-7!7$' )*)/--+ -"0)/.*.*0/-*.' $/*- .F
0)* !*- +*..=1 'D 0 *0/-. + ..*. * /$( '"*-&. 1$ +..- + '*
/&1 -C*2 +- %0- '"0(. + ..*.D -/*I > ' (-)* ,0 )9*
*). "0$- (*. %0- /**.D +*- $..* *)/* /(;( *( .0 %0 +- - .+*) -
*0/-*.' $/*- .,0 ) ..$/ (F
*(*.0" -$-( '#*-$.*0- +*-/- --*.)*'$1-*I
1*< )*)/-- '"0( --* )* *)/ A* .. '$1-* *0 . /$1 - '"0( .0" ./9* +-
( '#*--+->3$( $:9*D1*0B-(0$/*! '$5. 1*<+0 -( $5 -F
)1$ 0( G($'+- '$1-*.O'"2*-&.F*(F
www.algaworks.com 6
) )*)/--*>$"*G!*)/ *+-*% /*I
./ '$1-*D )>. . )1*'1 (*. 0( +-*% /* +..* +..*F '$)& +- $3- * >$"*G
!*)/ !*$ )1$*+-. 0 G($',0)*1*<. $).- 1 0+-- -*'$1-*F
.* 1*< / )# + -$* .. '$)&D .. #//+EJJ'"F2*-&.J'$1-*G%1 J +- - <G
'*)*1( )/ F
%0 )*)/$)0$ .. /-'#*
.- 1 - 0( '$1-* *(* .. 7 (0$/* /-'#*D +*- $..*D .. +-*% /* .> !5 . )/$* .
(0$/.+ ..*./$1 - ( ..* ' F
%0 $10'"- .. '$1-* +- . 0. ($"*. ,0 /(;( . $)/ - ..( +*-
+-*"-(:9*1F*(+-/$'# )* **& 2$// -H
www.algaworks.com 7
0(7-$*
R
)/-*0:9** . )1*'1$( )/*2 RU
RFR ,0 ;1I RU
RFS +-*/**'* RV
RFT . )1*'1$( )/*2 *(1 RX
RFU *)/$) -. RY
RFV
)./')**+# *(/ RZ
RFW
)/ "-)**'$+. *(*+# *(/ SR
RFX +# 1 ) SW
RFY -$( $-*+-*% /*2 *(+# 1 ) SW
S -.$./<)$ *.*( TW
SFR ,0 ;+ -.$./<)$I TW
SFS + ( )/*% /* '$*)'LM TW
SFT *-,0 0.-I TY
SFU 1 -.$./ )
$ -)/ TY
SFV *)B"0-:9* $ -)/ *(1 ) TZ
SFW -$:9***($)* ' UQ
SFX
(+' ( )/:9** ,0'.LM #.#* LM US
SFY + ( )/*7.$* UT
SFZ -,0$1*+ -.$./ ) F3(' UX
SFRQ -)*./ '.*)* *. UZ
SFRR ->3$(*.+..*. VQ
T
)/-*0:9** VR
TFR ,0 ;1 -1 - .I VR
TFS -$)$+$.*(+*) )/ . VS
TFT $'$*/ . *(+*) )/ . / - $-*. VS
TFU .*'# )*0($(+' ( )/:9* VT
TFV $$*))**+-*% /*1 ) VU
TFW )" ) VU
TFX -$)*0(+7"$)
VW
TFY
$")*1'*- . :@ .*(
VZ
TFZ .*+*. ()" ). WR
TFRQ &$)" ) WV
TFRR $'* 1$ WX
TFRS -,0$1*! .G*)B"F3(' XQ
TFRT -,0$1*2 F3(' XQ
U 1 ":9* XT
UFR
)/-*0:9*6)1 ":9* XT
UFS 1 ":9*$(+'=$/ XT
UFT 1 ":9* 3+'=$/ XU
V *(+*) )/ . $)/ -! XW
VFR $'$*/ . XW
VFS :'#* *-+*+7"$) XX
VFT *-(0'7-$*. XX
VFU -*+-$ .*(0). XY
VFV )/- / 3/*. YS
VFW = / 3/*. YT
VFX
(" ). YV
VFY )0. $3. '$./" ( YW
VFZ (+*. # " ( */@ .-7$* ZQ
VFRQ
/ ). . ' :9* ZT
VFRR */@ . '$)&. ZU
VFRS $);$. ZV
VFRT )." ). ZY
VFRU '. *. ZZ
VFRV -,0$1*.1-$+/ RQU
W 7"$) *).0'/ '):( )/*. RQW
WFR -$)*)/$/4)" - RQW
WFS -.$./$)*+ ..*. '):( )/*. RQX
WFT )" ),0 *).0'/'):( )/*. RQZ
WFU 7"$) - .0'/**).0'/ RRQ
WFV +-9* +*.$/*-4 RRS
X (+'/ .*( ' /. RRU
XFR 0';*+-*' ( - + /$-I RRU
XFS
)'0$)*0( :'#* -*+; RRU
XFT -$)*0(/ (+'/ RRX
XFU .)**/ (+'/ RRY
Y *)1 -.9* 1'$:9* RSQ
YFR
)/-*0:9* RSQ
YFS *)1 -.*- .+-9* RSS
YFT '/ -)/$1.+- B)$-*)1 -.*- . RSX
YFU 0./*($5)*( )." ). --* *)1 -.9* RSY
YFV '$*- .+-9* RTR
YFW 0./*($5)*( )." ). --*. 1'$:9* RTU
YFX -$)**)1 -.*- .+ -.*)'$5*. RTV
YFY -$)*1'$*- .+ -.*)'$5*. RTX
Z 7"$) ./-* '):( )/* RTZ
ZFR
(+' ( )/)**- +*.$/>-$* RTZ
ZFS
(+' ( )/)*.- "-. ) ">$* RUQ
ZFT -*"-()**()" ) ./-* RUR
ZFU -*"-()***)1 -.*- ..* RUS
ZFV -$)**!*-(0'7-$* ./-* RUT
RQ )'$/$*) RUW
RQFR ,0 ; )'$/$*)I RUW
RQFS $$*))**-/ !/*)*+*(F3(' RUX
RQFT $$*))*- ./-$:@ .)*(* '* RUX
RQFU 0./*($5)*( )." ). 1'$:9* RVQ
RQFV *(+*)*0()*1- ./-$:9* RVT
RR )$+0')* 1 )/*. RVV
RRFR
)/-*0:9* RVV
RRFS 1 )/*. :9* RVV
RRFT 1 )/*. (0): 1'*- +-*+-$ $(( $/ RVW
RS
G*)/ 3/.) + ) )4
)% /$*) RVZ
RSFR
)% :9* + )<)$. RVZ
RSFS *)B"0-)*
)*+-*% /* RWR
RSFT ).
D
( . O
)% / RWS
RSFU .*+*. ).
RWV
RSFV -*0/*- )/$/4)" - RWW
RSFW *)/-*')*./-).:@ .*($)/ - +/*- . RWX
RSFX
)% :9* (*)1 -.*- . RWZ
RT %3 RXR
RTFR
)/-*0:9* RXR
RTFS ) -$5:9*+-$' RXR
RTFT +-*+-$ 1 )/ RXT
RTFU +-*+-$ '$./ ) - RXT
RTFV ) -$5:@ .(A'/$+'. RXU
RTFW -* ..( )/*+-$' RXW
RTFX '1-.G#1 +-- ) - 3 0/ RXX
RTFY 7"$) ./-* '):( )/**(%3 RXY
RU -$( . RYQ
RUFR
)/-*0:9* RYQ
RUFS *)B"0-)**+-*% /* RYR
RUFT 0/+0/
'
)+0/ 3/ RYR
RUFU ' /) )0 RYS
RUFV ' /) 0//*) RYT
RUFW ' )- RYV
RUFX 0/**(+' / RYW
RUFY .." . RYX
RUFZ *(()0//*) RYY
RUFRQ ) '-$ RYY
RUFRR /' RYZ
RUFRS )0- RZS
RUFRT %3//0. RZU
RUFRU -*"-()*'/ -:9* '):( )/*. RZU
RUFRV -*"-()* 3'0.9* '):( )/*. RZX
RV "0-):+'$:9* SQQ
RVFR .*'# )*0(.*'0:9* SQQ
RVFS
*"$) SQQ
RVFT
*"*0/ SQU
RVFU $'/-* 0/*-$5:9* SQV
RW *)'0.9* SQW
RWFR ->3$(*.+..*. SQW
+=/0'*R
)/-*0:9**
TFRF ,0 ;1 -1 - .I
1 -1 - .D /(;( *)# $* *(* D ; 0( / )*'*"$ +-
. )1*'1$( )/* 2 ,0 0/$'$5 0( (* '* $)/ -! . "-7B. . * (
1 )/*.F ./ / )*'*"$ !*$ B)$ + '* L/ (&&.'"-2 +(,,MD * ,0 /*-)
0( +-9* . )1*'1$( )/* !$'$/ * /-'#* *. !*-) *- . ! --( )/.D
* -$- ( +-*0/*. ,0 1'*-$5 ( +-*0/$1$ )* . )1*'1$( )/* $)/ -! .
1$.0$.F
; . * )* +-9* +-*% /* L* ' $ 2 *)/-*'' -MD * ,0 /*-) *
. )1*'1$( )/* .$./ (. ( )*. *(+'$*F +-9* . +- * .$./ ( (
/-<. - .+*).$'$ . L(* '*D 1$.0'$5:9* *)/-*' MD *) * (* '* ; - .+*).71 '
+*- - +- . )/- *. *% /*. ) ">$*D ()/ - * ./* +'$:9* !*-) - *
*)/-*'*- * ..* *. *.F 1$.0'$5:9* ; - .+*).71 ' + ' $)/ -! * 0.07-$*F
' ,0 B) !*-( *(* *. *. .9* +- . )/*. )($)# . :@ . *
0.07-$* +- * *)/-*'*-F *)/-*'*- ; - .+*).71 ' +*- '$"- * (* '*
1$.0'$5:9*D $)/ -+- /)* . .*'$$/:@ . * 0.07-$*D /-05$)* +- 0( *+ -:9*
)* (* '* L*) .9* - '$5. ! /$1( )/ . (0):. )* .$./ (M - /*-))*
1$.0'$5:9* ,06.*'$$/:9*F
( D * *)/-*' ; ! $/* /-1;. 0( . -1' / #( , +/%-D
*+$*)'( )/ D +*- -,0$1*.
*)B"0-:9* +*- 17-$*. ()$+0'*- .
:@ . *. -1*- . 1 )/*.F , +/%- - . - ,0$.$:@ . *. 0.07-$*. )
2 D- $- $*)+-*(* '* )1$0(- .+*./F
(* '* ; - +- . )/* +*- *% /*. ) ">$*D ,0 3 0/ 0( '>"$ ) ">$*
*- -*.*-$0)*.( 1$.0'$5:9*F
www.algaworks.com 51
1$.0'$5:9* ; *(+*./ +*- 0( #$ --,0$ *(+*) )/ . L(&)(''- -+MD *
,0 /*-) +*..=1 ' 0)$- *(+*) )/ . +- *)./-0$- $)/ -! . ($. -$. *(+' 3.F
TFSF -$)$+$.*(+*) )/ .
1 - $-* +* - 1 -1 - . ./7 ( . 0 (* '* *(+*) )/ .
$)/ -! * 0.07-$*D ,0 " - '/ +-*0/$1$ *. . )1*'1 *- .D + -($/$)*
*)./-0:9* $)/ -! . +- 2 0.)* 0( *)%0)/* *(+*) )/ . +-;G
*)./-0=*.D*$)1;. -$-$)/ -! .$)/ $-( )/ *5 -*F
3$./ ( 17-$*. *(+*) )/ . D . *. ($. .$(+' .D *(* 0( .-).- %D ,0
+- . )/ .$(+' .( )/ 0( / 3/*D *0 0( - %D ,0 - +- . )/ *. /0'- .
0(*' :9*,0 +* 1$-*)* *.F
.0+*-/ 3/ ).9* -$:9* )*1*. *(+*) )/ .D ,0 +* ( !*-) -
!0)$*)'$ . $$*)$.F . +-$)$+$. *(+*) )/ . ,0 $(+' ( )/:9*
- ! -<)$ * !*-) .9*E !*-(0'7-$*D (+*. )/- / 3/* . )#.D
->/0'*.D'$)&.D*/@ .D( )." ).D+$);$.D/ ' *.D /F
TFTF $'$*/ . *(+*) )/ . / - $-*.
/0'( )/ D 3$./ ( $1 -.. *-")$5:@ . ,0 /-'#( ) -$:9* *(+*) )/ .
+ -.*)'$5*.D *(* 3 (+'*D +* (*. $/- -' L . $# '$ )/MD
*!/L
.MD /L$# .MD-$( #)*'*"4L-$( .M /F
. $'$*/ . *(+*) )/ . / - $-. $)'0 ( (0$/*. *(+*) )/ . $)/ - ..)/ .D
*(* / '. *. 1):.D ( )0. .0.+ ).*.D */@ .D --. +-*"- ..9*D
$7'*"*.D*(+*) )/ .+-+/0- /. *- .D /F
www.algaworks.com 52
.- (*. -$( . )* +-*% /* ./ '$1-*D (. )/ .D 0.- (*. + ). *.
*(+*) )/ .7.$*.*F
TFUF .*'# )*0($(+' ( )/:9*
!*$ -$ /-1;. * / (&&.'"-2 +(,, LMD ,0 ; 0( )/$ !*-(
+ '. ($. $(+*-/)/ . (+- .. / )*'*"$ * (0)* .+ $'$./. ( $1 -.*.
..0)/*.F
; *(+*./* +*- 17-$*. "-0+*. /-'#*D ,0 .9* #(*. L/
)"3-"(' *.,-MF ( ; 0( +-*% /* 0( )*1 / )*'*"$F -/ !/*
+-*05$* /-1;. . . .9* *0( )/:@ .D $)/ -! . '"0(. '.. . ,0
.+ $B(*(* 1 !0)$*)-0()*1*+-*0/*F
!*$ -$ ; *)/-*' + '* /-1;. .F 0)* 0( ; B)'$5D
(+- .. !*-) *-. / )*'*"$ /<( #) )/ ) - .+ $B:9*
$(+' ( )/-0(+-*0/*B)'*(+/=1 '*(*+-*+*./*+ ' .+ $B:9*F
* .* D $(+' ( )/:9* ($. *)# $ /0'( )/ ; (#++D ,0 +*
. -*/$ ( #//+.EJJ%1. -1 -! .F%1F) /JF
www.algaworks.com 53
TFVF $$*))**+-*% /*1 )
*(* ./(*. 0.)* * 1 )D )9* +- $.- (*. $3- $(+' ( (/:9*
()0'( )/ F* (*.+ ).$$*)- + )<)$)**+-*% /*F
<!-- Mojarra (implementacao do JSF) -->
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.faces</artifactId>
<version>2.2.10</version>
<scope>compile</scope>
</dependency>
.- (*.*SFSD'):* )/-*1XF
$$*)- (*. * +(#- - /+/+ , *( 1 -.9* SFS +- * '$+. )*.
03$'$-( '#*-0-)/ * . )1*'1$( )/*F
TFWF )" )
)/$"( )/ D '"0). +-*"-(*- . . )1*'1$( /** * *(+*-/( )/* 0(
+7"$) )* +->+-$* -,0$1* '4*0/D ) 1 - D $)! '$5( )/ D $) 3$./ (
+-*"-(*- .,0 !5 ($..*F
www.algaworks.com 54
( D )9* *). "0$(*. !5 - $..*F -,0$1* ,0 $)'0$ *. *(+*) )/ . +7"$)
1 B- . +-* '.. ,0 " - )$ * *(+*-/( )/* 'D #(
()" )F
. ()" ). ) ($. .9* ,0 1 ).D ,0 . -1 ( *(* )$. )/-
$)/ -! "-7B L +7"$)M * $7' +'$:9* L- "-. ) ">$*D ..* *
)* *.D /MF
. ). " - )$*. * +* ( - - *. $"$/*. + '*. 0.07-$*. /-1;.
'"0( +7"$)D +-* ..- (;/**. /-1;. :@ . *. 0.07-$*. !*-) - *. +-
+- . )/:9*)+7"$)F
- 0( ) . - - *)# $* *(* 0( ()" ) D +- $.(*. - "$./-7G'*F
() $- ($. !7$' !5 - $..* ; /-1;. )*/:9* @ManagedBeanD * +*/
javax.faces.beanF *- +-9*D /*. . '.. . * +-*% /* . -9* .) . +-
)*)/-- ).)*/*.F
*..* +-$( $-* 3 (+'* . -7 * ()" ) OlaBeanF . /-$0/*. nome
sobrenome . -9* $)!*-(*. + '* 0.07-$*.D +*- $..*D +*..0 ( *. --+, ,--+,
*-- .+*) )/ .F /-$0/* nomeCompleto . -7 (*)/* + '* (;/** dizerOla
+- . )/* ) +7"$)D +*-/)/*D )9* +- $.(*. * ,--+ +- .. /-$0/*F
(;/** dizerOla . -7#(*+-/$- 0(*/9*+7"$)F
@javax.faces.bean.ManagedBean
public class OlaBean {
private String nome;
private String sobrenome;
private String nomeCompleto;
public void dizerOla() {
this.nomeCompleto = this.nome.toUpperCase()
+ " " + this.sobrenome;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getSobrenome() {
return sobrenome;
}
www.algaworks.com 55
public void setSobrenome(String sobrenome) {
this.sobrenome = sobrenome;
}
public String getNomeCompleto() {
return nomeCompleto;
}
}
TFXF -$)*0(+7"$)
(*. -$- 0( +7"$) .$(+' . ( D ,0 +*- ),0)/*D )9* !-7 '$":9* *( *
()" ),0 +-*"-((*.F
-$- (*. 0( -,0$1* #(* %61!-&%D '$)* *( * */9* $- $/* )* +-*% /*
..)* 0D
"%F / ' 0
"%D $"$/ * )*( * -,0$1*
'$,0 ( "'",!F-,0$1*. -7-$*)*$- />-$* ,+9&"'90)) *+-*% /*F
www.algaworks.com 56
$3- (*.*>$"*G!*)/ *-,0$1* %61!-&% *(*. "0$-E
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>Ol JSF</title>
</h:head>
<h:body>
<h:form>
<h1>Ol</h1>
Nome: <h:inputText />
<br/>
Sobrenome: <h:inputText />
<br/>
<h:commandButton value="Dizer ol" />
</h:form>
</h:body>
</html>
'-:9* !*$ 0. +- $5 - *. +(0,+, *. 0.07-$*. 1 -.9* *
,0 ./(*. 0.)*D +- ,0 ' . +*..( 3$$- *. ' ( )/*. !*-(
,0F()*..* 3 (+'*D '-(*.,0 ;*
VF
<!DOCTYPE html>
)1*-+'$:9*
,0$)/ !. D *. 1 )/*. ,0 *-$"$)-( * )1$* * !*-(0'7-$* * . -1$*- .9*
3 0/*.F *- 3 (+'*D * '$- ( 0( */9* +- .0( / - 0( ./-*D
+-*"-(:9* :9* ./ */9* 1 . - 3 0/F ( '"0). .*.D * (;/**
3 0/* +* - /*-)- 0( $ )/$B*- $5 )* ,0' ; +->3$( +7"$) . -
3$$D*0.$(+' .( )/ )9*- /*-)-)+- 3$$-( .(+7"$)F
) -$5-- .+*./
*- A'/$(*D !. - ) -$5:9* - .+*./ " - .= *( /**. *. *(+*) )/ .
)*. . 0. ./*. /0$. )1$ +- * '$ )/ F $'* - *( : . (+- ,0 * 0.07-$*
$)/ -" *(+'$:9* 0(- ,0$.$:9*; )1$*. -1$*-F
www.algaworks.com 69
TFRSF -,0$1*! .G*)B"F3('
-*% /*. ,0 0.( 1 -1 - . +* ( / - 0( -,0$1* *)B"0-:9*D #(*
,7('3 61&%F ./ -,0$1* ; *+$*)'D (. . +- $.- ' D -$ )* $- />-$* ,+9
&"'90))97
*+-*% /*D*(**)/ A*(=)$(*$3*E
<?xml version="1.0" encoding="UTF-8"?>
<faces-config xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"
version="2.2">
</faces-config>
)/- $1 -.. *$.. ,0 +* (*. *)B"0-- ) .. -,0$1*D 0( '. ; * - "$./-*
()" ).D *(* '/ -)/$1 6. )*/:@ .F *- 3 (+'*D 1 % *(*
- "$./--=(*.*()" ) NomesBean ) ./ -,0$1*F
<managed-bean>
<managed-bean-name>nomesBean</managed-bean-name>
<managed-bean-class>
com.algaworks.financeiro.controller.NomesBean
</managed-bean-class>
<managed-bean-scope>view</managed-bean-scope>
</managed-bean>
. 1 -.@ . )/ -$*- . * SD )9* 3$./$( . )*/:@ . +- - "$./-- ()"
).D +*- $..*D * -,0$1* ,7('3 61&% - *-$"/>-$*F '$5( )/ D +- $.- (*.
.. -,0$1* + ). +- B)$- *0/-. *)B"0-:@ . +'$:9*D ,0 1 - (*. ($.
$)/ F
TFRTF -,0$1*2 F3('
. +'$:@ . 2 ( 1 +* ( / - 0( -,0$1* .+ $'D #(* 061&%D ,0 1
B- ) +./ ,+9&"'90))97
* +-*% /*F ./ -,0$1* /(;( ; #(*
)%(2&'- ,+")-(+D +*$. ' .- 1 '"0(. *)B"0-:@ . /'# .
$(+')/:9**.- 0-.*.+'$:9*F
-,0$1* 061&% )9* ; *-$"/>-$*D (. +* (*. -$7G'* '$)* *( * */9*
$- $/* ( )%(2&'- ,+")-(+ L )/-* * +-*% /*M +*$. ( '+-
)%(2&'-,+")-(+-.F
www.algaworks.com 70
-,0$1*. -7-$**(0(*)/ A*. ( '#)/ *>$"*$3*E
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<display-name>Financeiro</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
-,0$1* " -* .- 1 * )*( +'$:9*D /-1;. display-nameD '"0).
-,0$1*. *. 1$).D /-1;. welcome-file-listD ,0 .9* 0.*. .* * 0.07-$*
.. *.$./ (+ ).+ '* ('-1-)-!D. ($)!*-(-*)*( 0(- 0-.*F
)%(2&'- ,+")-(+ 0( +'$:9* +* .- 1 - /(;( . -1' /.D B'/-*.D
(+ ( )/*. *0/-.*)B"0-:@ .F
www.algaworks.com 71
- * !-( 2*-& * 1 -1 - . !0)$*)-D ' - "$./- 0/*(/$( )/ 0(
. -1' / #( , +/%-F ./ . -1' / ; (+ +- * +-9*
9,9:D
+*-$..*D,0)* ..(*.0(+7"$)D .- 1 (*. 9,9(& "'61!-&%F
* (*..*- .- 1 -*- "$./-* ,+/%- . 0(+ ( )/*F
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
*( ./ )*1* (+ ( )/* , +/%-D +* (*. ..- +7"$) '$./" (
)*( ./-1;.
!--)599%(%!(,-5A<A<9"''"+(9(&,61!-&%F
(*. +-*1 $/- ,0 ./(*. $/)* * -,0$1* 061&% +- $)'0$- *)B"0-:9*
$3*E
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
+-8( /-* *)/ 3/* $$*)* $( $5 ,0 ./(*. ( ($ )/
. )1*'1$( )/*F 0)* *( / -(*. '"0( --*D +7"$) +* 3$$- $)!*-(:@ .
/;)$.$$*)$.D+-)*.%0-- .*'1 -*+-*' (F
www.algaworks.com 72
+=/0'*U
1 ":9*
UFRF
)/-*0:9*6)1 ":9*
( D )1 ":9* ; 0( *)%0)/* - "-. ,0 B) +->3$( +7"$) . - 3$$
,0)* 0( :9* ; 3 0/ + '* 0.07-$*F *- 3 (+'*D ,0)* 0( 0.07-$* '$ (
0( */9* +- . $).- 1 - ( 0( .$/ D ,0' +->3$( +7"$) ' 1 -7 1$.0'$5-I
*. *. ./$1 - ( $)*(+' /*.D +-*11 '( )/ 1 -7 1$.0'$5- ( .( +7"$)D
*( . ( )." ). --* +-*+-$.D +*-;( . /0* ./$1 - *-- /* $).-$:9* !*-
! /0*(.0 ..*D ' +* -71 -0(+7"$) *.1$).*. -1$:*F
)1 ":9* +* . - $(+'=$/ *0 3+'=$/F ./0- (*. *(* *)B"0-- *. *$.
/$+*.F
UFSF 1 ":9*$(+'=$/
0)* $)'0=(*. 0( <h:commandButton> *( 0( 1'*- ) +-*+-$ actionD
* ( )$.(* /-/( )/* )1 ":9* / )/-7 )*)/-- 0( +7"$) ,0
0/*(/$( )/ F * 3 (+'* $3*D * ( )$.(* )1 ":9* )*)/--7
)($)#-7- ,0$.$:9*+-+7"$) %61!-&%F
<h:commandButton value="Prxima pgina" action="Ola" />
1'*- +..* +- +-*+-$ action ; #(* (.-(&D *0 - .0'/*
:9*F
www.algaworks.com 73
1 ":9*$)8($
0)* 0( action / ( 0( 3+- ..9* '$":9* (;/**D * - /*-)* * (;/**
1 . -* (.-(& )1 ":9*F
<h:commandButton value="Adicionar" action="#{nomesBean.adicionar}" />
0)* * (;/** adicionar - /*-)- nullD * 0.07-$* + -() -7 ) ( .( +7"$)F
0)**- /*-)*!*-N'ND- ,0$.$:9*. -7 )($)#+-+7"$) %61!-&%F
public String adicionar() {
this.nomes.add(nome);
if (this.nomes.size() > 3) {
return "Ola";
}
return null;
}
$- $*)( )/*
*- +-9*D 0( - ,0$.$:9* ; )($)# +- +7"$) * (.-(&D *0 . %D
- ,0$.$:9* ; A)$ * !-( 2*-& + ). .+# - ,0$.$:9* +- 0( )*1 +7"$)F
!*- ) ..7-$* ,0 . % ! $/* * - $- $*)( )/*D +* (*. +..- * +-8( /-*
faces-redirect=true +-* (.-(&F
public String adicionar() {
this.nomes.add(nome);
if (this.nomes.size() > 3) {
return "Ola?faces-redirect=true";
}
return null;
}
UFTF 1 ":9* 3+'=$/
. - "-. )1 ":9* 3+'=$/. .9* '-. )* -,0$1* ,7('3 61&%F -
'-- 0( - "- 3+'=$/D +- $.(*. $)!*-(- * ($)#* +7"$) *-$" (D 0(
(.-(& *(0()*( ,0',0 - *($)#*+7"$) ./$)*F
www.algaworks.com 74
<navigation-rule>
<from-view-id>/Nomes.xhtml</from-view-id>
<navigation-case>
<from-outcome>oi</from-outcome>
<to-view-id>/Ola.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
- "- ,0 (*. '-- B) ,0 :9* )*( N*$N +-/$- *-$" (
9(&,61!-&% 1 )($)#- +- +7"$) 9%61!-&%F - 0.- ./ - "-D
+* (*. .$(+' .( )/ $$*)- 0( */9* ) +7"$) (&,61!-&% *(
+-*+-$ action - ! - )$)** (.-(&F
<h:commandButton value="Prxima pgina" action="oi" />
$'-
* (*. 0.- 0"%+ )* ' ( )/* from-view-id +- . ' $*)- $1 -.*. -,0$1*.
*-$" (D*(*+*- 3 (+'* * *0 /admin/*F
<navigation-rule>
<from-view-id>*</from-view-id>
<navigation-case>
<from-outcome>oi</from-outcome>
<to-view-id>/Ola.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
$- $*)( )/*
*- +-9*D - ,0$.$:9* . -7 )($)# +- +7"$) ./$)*F +- $.-(*.
!5 -*- $- $*)( )/*D./$)'0$-* ' ( )/* <redirect/>F
<navigation-rule>
<from-view-id>*</from-view-id>
<navigation-case>
<from-outcome>oi</from-outcome>
<to-view-id>/Ola.xhtml</to-view-id>
<redirect/>
</navigation-case>
</navigation-rule>
www.algaworks.com 75
+=/0'*V
*(+*) )/ . $)/ -!
VFRF $'$*/ .
- . )1*'1 - 0( .$./ ( *(+' /* ( 1 -1 - .D 1*< 1 *)# - + '*
( )*. *. +-$)$+$. *(+*) )/ . 7.$*.F 0)* !'(*. ( *(+*) )/ . 7.$*.D
,0 - (*.$5 -*.*(+*) )/ .+-@ . .+ $B:9*/ )*'*"$F
.$'$*/ . /"..9*E
K (+E 3$./ +- - .0+*-/ 6. *0/-. $'$*/ .D )9* +*..0$
*(+*) )/ . 1$.0$.F +- ) - (*. ./ $'$*/ )* *-- - * '$1-*D
. (+- ,0 !*-) ..7-$*
K
E +*..0$ *(+*) )/ . ,0 " -( *)/ A* 1$.0'D *(* !*-(0'7-$*.D
(+*. )/-D ->/0'*. .= / 3/*.D */@ .D '$)&.D . ' :@ .D
+$);$.D/ ' *.D( )." ). /F
K %-,E;$'$*/ +--$:9* / (+'/ . +7"$).F
K (&)(,"-E0.+--$-*(+*) )/ .0./*($5*.F
./ +=/0'*D!*- (*.)*.*(+*) )/ .1$.0$.D$'$*/
F
- 0.- . $'$*/ .D / (*. ,0 $(+*-/7G'. /-1;. *. '&,),
*-- .+*) )/ .F
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html"
www.algaworks.com 76
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:composite="http://xmlns.jcp.org/jsf/composite">
(+' ( )/(*. )*..* *)1 -.*- .+ -/* /. - "$./-(*. ' *( *
$ )/$B*- ,&+--D /-1;. )*/:9* @FacesConverterF "*-D +* (*. 0.-
* *)1 -.*- .$(+' .( )/ $)!*-()* *
) +-*+-$ converter /"
<h:inputText>F
<h:inputText size="12" value="#{calculadoraDataBean.dataBase}"
converter="smartDate" />
www.algaworks.com 136
'/ -(*. +7"$) '0'*- /D ,0 0.(*. )* 3 (+'* 0( . :9*
)/ -$*-D $)'0=(*. +*..$$'$ $)!*-(- '"0(. +'1-. .+ $$. +-
- ! - )$-/.D*(*+*- 3 (+'*N*)/ (NF
YFYF -$)*1'$*- .+ -.*)'$5*.
+-* ..* +- -$- 1'$*- . + -.*)'$5*. ; . ( '#)/ 6 -$:9*
*)1 -.*- .F -$- (*. 0( 1'$*- /. ,0 - ./-$)" *. 1'*- . + ). ( $.
A/ $.F
- -$- 0( 1'$*- 0./*($5*D +- $.(*. $(+' ( )/- $)/ -!
javax.faces.validator.Validator )*/-'.. *( @FacesValidatorF
@FacesValidator("diaUtil")
public class DiaUtilValidator implements Validator {
@Override
public void validate(FacesContext context, UIComponent component,
Object value) throws ValidatorException {
Date data = (Date) value;
Calendar calendar = Calendar.getInstance();
www.algaworks.com 137
calendar.setTime(data);
int diaSemana = calendar.get(Calendar.DAY_OF_WEEK);
if (diaSemana < Calendar.MONDAY
|| diaSemana > Calendar.FRIDAY) {
throw new ValidatorException(new FacesMessage(
FacesMessage.SEVERITY_ERROR, "Data invlida.",
"A data informada no um dia til."));
}
}
}
"$./-(*. )*..* 1'$*- *( * $ "-"%F "*-D +* (*. 0.7G'* /-1;. /"
<f:validator>F
<h:inputText size="12" value="#{calculadoraDataBean.dataBase}">
<f:convertDateTime pattern="dd/MM/yyyy"
timeZone="America/Sao_Paulo" />
<f:validator validatorId="diaUtil" />
</h:inputText>
www.algaworks.com 138
+=/0'*Z
7"$) ./-* '):( )/*
ZFRF
(+' ( )/)**- +*.$/>-$*
./ +=/0'*D -$- (*. 0( +7"$) ./-* '):( )/*.F +-$( $- *$. ,0
1(*.!5 -D;$)'0$-0((;/** adicionar() )*- +*.$/>-$* LancamentosF
public void adicionar(Lancamento lancamento) {
this.manager.persist(lancamento);
}
+*$.D -$- (*. 0( )*1* - +*.$/>-$* #(* PessoasD *( (;/**. +- *).0'/
/*..+ ..*. 0(A)$+ ..*+*-0(>$"* .+ =B*F
package com.algaworks.financeiro.repository;
// imports
public class Pessoas implements Serializable {
private static final long serialVersionUID = 1L;
private EntityManager manager;
public Pessoas(EntityManager manager) {
this.manager = manager;
}
public Pessoa porId(Long id) {
return manager.find(Pessoa.class, id);
}
public List<Pessoa> todas() {
TypedQuery<Pessoa> query = manager.createQuery(
"from Pessoa", Pessoa.class);
return query.getResultList();
www.algaworks.com 139
}
}
ZFSF
(+' ( )/)*.- "-. ) ">$*
. - "-. ) ">$* 0( +'$:9* )9* 1 ( B- ( ()" ).F
- $.(*. -$- '.. . ,0 /-/( + ). +-* ..*. ) ">$*D !$'$/)*
()0/ ):9* - +-*1 $/( )/*'>"$*.$./ (F
(*. -$- 0( /$+* 3 :9* #(* NegocioExceptionD +- - +- . )/- --*.
) ">$*F
package com.algaworks.financeiro.service;
public class NegocioException extends Exception {
private static final long serialVersionUID = 1L;
public NegocioException(String msg) {
super(msg);
}
}
"*-D -$- (*. )*.. '.. ) ">$* ,0 /-/ ./-* '):( )/*.F ..
'.. + ) -7 * - .+*.$/>-$* '):( )/*.D +*- $..*D ' 1 - - * *% /*
*- +*.$/>-$*)**)./-0/*-F
package com.algaworks.financeiro.service;
// imports
public class CadastroLancamentos implements Serializable {
private static final long serialVersionUID = 1L;
private Lancamentos lancamentos;
public CadastroLancamentos(Lancamentos lancamentos) {
this.lancamentos = lancamentos;
}
public void salvar(Lancamento lancamento) throws NegocioException {
if (lancamento.getDataPagamento() != null &&
lancamento.getDataPagamento().after(new Date())) {
throw new NegocioException(
"Data de pagamento no pode ser uma data futura.");
}
www.algaworks.com 140
this.lancamentos.adicionar(lancamento);
}
}
!*-( ,0 $(+' ( )/(*.D +* (*. 0.- '.. CadastroLancamentos ( 0(
.$./ ( .&/*+*02 D$)'0.$1 0.)*,0',0 -!-( 2*-&F
ZFTF -*"-()**()" ) ./-*
(*. -$- * ()" ) ,0 . -7 0.* + ' +7"$) ./-* '):( )/*.F
(;/** salvar() 1 $)$$- 0( /-).:9*D $)./)$- 0( *% /* * /$+*
CadastroLancamentos .'1- * '):( )/*F .* **-- '"0( --*D 1 G. !5 -
+(%%$ +- . )/-0(( )." ( --*F
-$(*. /(;( 0( (;/** #(* prepararCadastro()D ,0 -- " 0( '$./
*( /*. . + ..*. ./-.F .- (*. .. '$./ +- +- )# - * ( )0
+ ..*.)+7"$)F
package com.algaworks.financeiro.controller;
// imports
@ManagedBean
@ViewScoped
public class CadastroLancamentoBean implements Serializable {
private static final long serialVersionUID = 1L;
private Lancamento lancamento = new Lancamento();
private List<Pessoa> todasPessoas;
public void prepararCadastro() {
EntityManager manager = JpaUtil.getEntityManager();
try {
Pessoas pessoas = new Pessoas(manager);
this.todasPessoas = pessoas.todas();
} finally {
manager.close();
}
}
public void salvar() {
EntityManager manager = JpaUtil.getEntityManager();
EntityTransaction trx = manager.getTransaction();
FacesContext context = FacesContext.getCurrentInstance();
www.algaworks.com 141
try {
trx.begin();
CadastroLancamentos cadastro = new CadastroLancamentos(
new Lancamentos(manager));
cadastro.salvar(this.lancamento);
this.lancamento = new Lancamento();
context.addMessage(null, new FacesMessage(
"Lanamento salvo com sucesso!"));
trx.commit();
} catch (NegocioException e) {
trx.rollback();
FacesMessage mensagem = new FacesMessage(e.getMessage());
mensagem.setSeverity(FacesMessage.SEVERITY_ERROR);
context.addMessage(null, mensagem);
} finally {
manager.close();
}
}
public List<Pessoa> getTodasPessoas() {
return this.todasPessoas;
}
public TipoLancamento[] getTiposLancamentos() {
return TipoLancamento.values();
}
public Lancamento getLancamento() {
return lancamento;
}
public void setLancamento(Lancamento lancamento) {
this.lancamento = lancamento;
}
}
ZFUF -*"-()***)1 -.*- ..*
-$(*. 0( *)1 -.*- ,0 ; +5 *)1 -/ - 0( ./-$)" *( * >$"* + ..*
(*% /**/$+* PessoaD 1$ G1 -.F
"$./-(*. * *)1 -.*- *)B"0-(*. ' *(* +-9* +- * /$+* PessoaD 0.)*
*/-$0/* forClass )*/:9* @FacesConverterF
package com.algaworks.financeiro.converter;
www.algaworks.com 142
// imports
@FacesConverter(forClass = Pessoa.class)
public class PessoaConverter implements Converter {
@Override
public Object getAsObject(FacesContext context,
UIComponent component, String value) {
Pessoa retorno = null;
EntityManager manager = JpaUtil.getEntityManager();
try {
if (value != null && !"".equals(value)) {
Pessoas pessoas = new Pessoas(manager);
retorno = pessoas.porId(new Long(value));
}
return retorno;
} finally {
manager.close();
}
}
@Override
public String getAsString(FacesContext context,
UIComponent component, Object value) {
if (value != null) {
return ((Pessoa) value).getId().toString();
}
return null;
}
}
ZFVF -$)**!*-(0'7-$* ./-*
+7"$) ./-* 0. * ,0 %7 !'(*. ( +=/0'*. )/ -$*- .F 9* $)'0=(*.
1'$:@ . )*. (+*. )/-D +*- $..*D +*- ),0)/*D ; $(+*-/)/ +- )# -
*-- /( )/ + '*( )*.*.(+*.*-$"/>-$*.F
<!DOCTYPE html>
<ui:composition template="/WEB-INF/template/Layout.xhtml"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<f:metadata>
<f:viewAction action="#{cadastroLancamentoBean.prepararCadastro}" />
</f:metadata>
www.algaworks.com 143
<ui:define name="titulo">Cadastro de lanamento</ui:define>
<ui:define name="corpo">
<h1>Cadastro de lanamento</h1>
<h:form id="frm">
<h:messages showDetail="false" showSummary="true" />
<h:panelGrid columns="2">
<h:outputLabel value="Tipo" />
<h:selectOneRadio
value="#{cadastroLancamentoBean.lancamento.tipo}"
label="Tipo do lanamento">
<f:selectItems
value="#{cadastroLancamentoBean.tiposLancamentos}"
var="tipoLancamento"
itemValue="#{tipoLancamento}" />
</h:selectOneRadio>
<h:outputLabel value="Pessoa" />
<h:selectOneMenu
value="#{cadastroLancamentoBean.lancamento.pessoa}"
label="Pessoa">
<f:selectItem
itemLabel="Selecione" noSelectionOption="true" />
<f:selectItems
value="#{cadastroLancamentoBean.todasPessoas}"
var="pessoa" itemValue="#{pessoa}"
itemLabel="#{pessoa.nome}" />
</h:selectOneMenu>
<h:outputLabel value="Descrio" />
<h:inputText size="60"
value="#{cadastroLancamentoBean.lancamento.descricao}"
label="Descrio" />
<h:outputLabel value="Valor" />
<h:inputText size="12"
value="#{cadastroLancamentoBean.lancamento.valor}"
label="Valor">
<f:convertNumber locale="pt_BR" maxFractionDigits="2"
minFractionDigits="2" />
</h:inputText>
<h:outputLabel value="Data de vencimento" />
<h:inputText size="12"
value="#{cadastroLancamentoBean.lancamento
.dataVencimento}"
label="Data de vencimento">
<f:convertDateTime pattern="dd/MM/yyyy"
timeZone="America/Sao_Paulo" />
</h:inputText>
<h:outputLabel value="Data de pagamento" />
www.algaworks.com 144
<h:inputText size="12"
value="#{cadastroLancamentoBean.lancamento
.dataPagamento}"
label="Data de pagamento">
<f:convertDateTime pattern="dd/MM/yyyy"
timeZone="America/Sao_Paulo" />
</h:inputText>
<h:outputLabel />
<h:commandButton value="Salvar"
action="#{cadastroLancamentoBean.salvar}" />
</h:panelGrid>
</h:form>
</ui:define>
</ui:composition>
.(*. /" <f:viewAction> ( <f:metadata> +- #(- * (;/**
prepararCadastro() *()" ))!. $)1*:9*+'$:9*F
%(*.*- .0'/* )*..+7"$)- ;(-$E
www.algaworks.com 145
+=/0'*RQ
)'$/$*)
RQFRF ,0 ; )'$/$*)I
) '$/$*) !*-) 0( !$'$ +- 1'$- *% /*. ( $! - )/ .
(. +'$:9*F 1 -1 - . $)/ "- *( ./ / )*'*"$ +- 1'$-
*% /*.+- )#$*.+ '.+7"$).,0 -$(*.F
1)/" ( 0.- ) '$/$*) ; ,0 . - ./-$:@ . B( $). -$. ). '.. .
(* '*D )9* ( +7"$).
D +*- $..*D +* ( . - 0.. +*- *0/-. (.
+'$:9*F
. - ./-$:@ . ) '$/$*) .9* ( !*-( )*/:@ .D ,0 +* ( . - 0..D
+*- 3 (+'*D ( )/$ .*0'.. . ()" ).F
$1 -.. )*/:@ . - ./-$:@ . ./9* $.+*)=1 $. )* +*/
javax.validation.constraintsF %(*. 0( 3 (+'* 0( '.. *( /-$0/*.
)*/*.*(- ./-$:@ . )'$/$*)F
public class Usuario {
@NotNull
@Size(min = 5, max = 20)
private String nome;
@NotNull
@Size(min = 5, max = 40)
private String sobrenome;
}
www.algaworks.com 146
) '$/$*) ; 0( .+ $B:9*D )9* 0( +-*0/*D +*- $..*D +- $.(*. 0(
$(+' ( )/:9* +- /0* !0)$*)-F . $(+' ( )/:@ . +* ( $$*)- - ./-$:@ .
0./*($5.D ';( . !*-) $. + ' .+ $B:9*F .- (*. * $ -)/
'$/*-D,0 $(+' ( )/ )'$/$*)F
RQFSF $$*))**-/ !/*)*+*(F3('
$ -)/ '$/*- +* . - $3* ( #//+EJJ#$ -)/ F*-"J1'$/*-JD (.
*(* ./(*. 0.)* 1 )D +* (*. !$'( )/ $$*)- * -/ !/* )* -,0$1*
)(&61&% )*..*+-*% /*F
<!-- Implementacao do Bean Validation -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.1.3.Final</version>
<scope>compile</scope>
</dependency>
./ +=/0'*D$(+' ( )/- (*.*. 3 (+'*.)*+-*% /**.$./ (B)) $-*F
RQFTF $$*))*- ./-$:@ .)*(* '*
)% /$*)
RSFRF
)% :9* + )<)$.
. ).
+*..0 ( .*+*.D,0 +* (. -E
,()( .+76(
O ,0 ./*+
)/ -:9**(0.07-$* (0(A)$- ,0$.$:9* F
)/ -:9**(0.07-$* )/- (0$/.- ,0$.$:@ . D*0
O ..$*)*+
. %D. ..9**0.07-$*F
./**(+-/$'#**(/**.*.0.07-$*.0-)/
O++'$/$*)*+
/* 3 0:9*+'$:9*F
* .*+*+-9*D. ) )#0(!*- .+ $B*F)/;(
O + ) )/
*( .(*$'* 1$* ),0 *$)% /*0F
)/ -:9**(0.07-$* )/- (0$/.- ,0$.$:@ . D
O*)1 -./$*)*+
*(*$)=$* /;-($)**)/-*'*+ '*+-*"-(*-F
*. ... )*/:@ . 1 ( . - $(+*-/. * +*/ javax.enterprise.contextF
. T +-$( $-.D +*..0 ( *. ( .(*. )*( . )*/:@ . * +*/
javax.faces.beanF 0)* 0.(*.
D / (*. ,0 /*(- 0$* +- )9*
$(+*-/-*+*/ --*H
)*/:9* @javax.faces.view.ViewScopedD + .- !0)$*)- *(
D ;
1 -1 - .F
www.algaworks.com 165
RSFVF -*0/*- )/$/4)" -
EntityManager )9* ; 0( )
D +*- $..*D )9* *). "0$(*. $)% /7G'*
0/*(/$( )/ F $)$$-(*. )*.. +'$:9* !*-( ,0 ./7D 0( 3 :9* . -7
'):F
org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied
dependencies for type EntityManager with qualifiers @Default
at injection point [BackedAnnotatedParameter] Parameter 1 of
[BackedAnnotatedConstructor] @Inject public com.algaworks
.financeiro.repository.Pessoas(EntityManager)
at com.algaworks.financeiro.repository.Pessoas.L ..*.F%1EQM
- - .*'1 - .. +-*' (D -$- (*. 0( (;/** +-*0/*- L)+(.+ &-!(M
EntityManagerF((;/**+-*0/*-" -0(*% /*,0 +* . -$)% /*F
*-('( )/ D 0.(*. (;/**. +-*0/*- . ,0)* ,0 - (*. $)% /- 0( *% /* ,0
)9* ; 0( )
D ,0)* * /$+* *)- /* * *% /* . - $)% /* +* 1-$- (
/ (+* 3 0:9* *0 ,0)* $)./)$:9* * *% /* - ,0 - '"0( +-* $( )/*
$$*)'F
package com.algaworks.financeiro.util;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.context.RequestScoped;
// outros imports...
@ApplicationScoped
public class EntityManagerProducer {
private EntityManagerFactory factory;
public EntityManagerProducer() {
this.factory = Persistence.createEntityManagerFactory(
"FinanceiroPU");
}
@Produces
@RequestScoped
public EntityManager createEntityManager() {
return factory.createEntityManager();
}
public void closeEntityManager(@Disposes EntityManager manager) {
manager.close();
}
}
www.algaworks.com 166
'.. EntityManagerProducer +*..0$ 0( (;/** +-*0/*- #(*
createEntityManagerF *% /* +-*05$* +*- .. (;/** / -7 * .*+*
- ,0$.$:9*D+*$.*(;/**!*$)*/**( @RequestScopedF
-$(*. /(;( 0( (;/** 10:9* L",)(,+ &-!(M EntityManagerD
#(* closeEntityManagerF ./ (;/** . -7 #(* 0/*(/$( )/
,0)* * *)/ 3/* *) * *% /* +-*05$* ./$1 - !*- ) --*F +-*1 $/(*. ./
1 )/*+-! #-* EntityManagerF
* (*. ..- . +7"$). * .$./ ( B)) $-* )*-('( )/ D /0* 1
!0)$*)-H
RSFWF *)/-*')*./-).:@ .*($)/ - +/*- .
( $)/ - +/*- ; 0( '.. 0. +- $)/ -1$- ( #(. (;/**.
'.. .F * (*. 0.- $)/ - +/*- . +- 17-$. *$..D *(* - "$./-- '*". *0
3 0/-/- !.- + /$/$1. ,0 )9*!5 (+-/ - "- ) ">$**.$./ (F
-$- (*. 0( $)/ - +/*- +- *)/-*'- . /-).:@ . )*.. +'$:9*F )/ .
*( :-D 1(*. 1*'/- * >$"* * (;/** adicionar() * - +*.$/>-$*
'):( )/*.+-1 -.9**-$"$)'D,0 )9*" - )$1/-).:@ .()0'( )/ F
public class Lancamentos implements Serializable {
private static final long serialVersionUID = 1L;
...
public void adicionar(Lancamento lancamento) {
this.manager.persist(lancamento);
}
}
)/ . -$- 0( $)/ - +/*-D +- $.- (*. 0( )*/:9* ,0 ..*$-7 *
$)/ - +/*- * (;/** *0 '.. ,0 . -7 $)/ - +/F ./ )*/:9* 1 . -
)*/*( @InterceptorBindingF
package com.algaworks.financeiro.util;
// imports
@InterceptorBinding
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE, ElementType.METHOD })
www.algaworks.com 167
public @interface Transactional {
}
'.. - .+*).71 ' + '. $)/ - +/:@ . 1 . - )*/ *( @Interceptor
/(;()*/:9*,0 (*. -$-D)*.*D @TransactionalF
(;/** ,0 - '$5-7 . $)/ - +/:@ . 1 - - InvocationContext *(*
+-8( /-*D - /*-)- 0( Object +* '):- ExceptionD ';( . - )*/* *(
@AroundInvokeF ./ (;/** 1 #(- context.proceed()D ,0 !5 *( ,0 *
(;/**$)/ - +/*. %- '( )/ #(*F
package com.algaworks.financeiro.util;
// imports
@Interceptor
@Transactional
public class TransactionInterceptor implements Serializable {
private static final long serialVersionUID = 1L;
private @Inject EntityManager manager;
@AroundInvoke
public Object invoke(InvocationContext context) throws Exception {
EntityTransaction trx = manager.getTransaction();
boolean criador = false;
try {
if (!trx.isActive()) {
// truque para fazer rollback no que j passou
// (seno, um futuro commit, confirmaria at mesmo
// operaes sem transao)
trx.begin();
trx.rollback();
// agora sim inicia a transao
trx.begin();
criador = true;
}
return context.proceed();
} catch (Exception e) {
if (trx != null && criador) {
trx.rollback();
}
throw e;
} finally {
if (trx != null && trx.isActive() && criador) {
trx.commit();
www.algaworks.com 168
}
}
}
}
- $.(*. - "$./-- * $)/ - +/*-F ( . !*-(. !5 - $..* ; )* -,0$1*
',61&%F
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
version="1.1" bean-discovery-mode="all">
<interceptors>
<class>
com.algaworks.financeiro.util.TransactionInterceptor
</class>
</interceptors>
</beans>
(+- ,0 +- $.-(*. 0( /-).:9* ( 0( )
D ./ )*/-(*. *
(;/***( @TransactionalF
public class CadastroLancamentos implements Serializable {
private static final long serialVersionUID = 1L;
@Inject
private Lancamentos lancamentos;
@Transactional
public void salvar(Lancamento lancamento) throws NegocioException {
...
}
}
RSFXF
)% :9* (*)1 -.*- .
9* ; +*..=1 ' $)% /- ).
( *)1 -.*- . D (. +-*11 '( )/ .. - 0-.*
./-7$.+*)=1 ' (0(!0/0-1 -.9**F
www.algaworks.com 169
'$5( )/ D $'$*/ ()$ . - .*'1 .. +-*' (D !5 )* *( ,0 $)% :9*
+ <)$. !0)$*) ( /*. . $)./8)$. )*/. *( @FacesConverterD . (
,0',0 -(*$B:9*F
- $.(*.+ ).$$*)-*-/ !/**()$ .)*-,0$1* )(&61&%F
<!-- OmniFaces (utilitarios para JSF) -->
<dependency>
<groupId>org.omnifaces</groupId>
<artifactId>omnifaces</artifactId>
<version>2.0</version>
<scope>compile</scope>
</dependency>
"*- )*..* *)1 -.*- PessoaConverter +* .$(+' .( )/ $)% /- * )
*
- +*.$/>-$* + ..*.F
@FacesConverter(forClass = Pessoa.class)
public class PessoaConverter implements Converter {
@Inject // funciona graas ao OmniFaces
private Pessoas pessoas;
@Override
public Object getAsObject(FacesContext context,
UIComponent component, String value) {
Pessoa retorno = null;
if (value != null) {
retorno = this.pessoas.porId(new Long(value));
}
return retorno;
}
...
}
www.algaworks.com 170
+=/0'*RT
%3
RTFRF
)/-*0:9*
%3 L,2'!+('(., /+")- '
M ; 0( "-0+* / )*'*"$. 2 ,0 + -($/
-$:9* +'$:@ . $)/ -/$1.F 0)* 0.(*. %3D . +'$:@ . 2 +* (
!5 - - ,0$.$:@ . *)/ A* * . -1$*- . ( - -- "- / 'D 0.)* + ).
!-"( )/*.+7"$),0 +- $.(. -/0'$5*.F
( 1 -.@ . )/ -$*- . * !-( 2*-& D +- ,0 . +'$:@ . +0 .. ( !0)$*)-
*( %3D - ) ..7-$* $$*)- $'$*/ . / - $-.F +-/$- * SD * .0+*-/
%3 ; !*-) $* +*- 0( $'$*/ 1-$+/ $)/ "-F *( ./ $'$*/ D
+* (*.0.-%3 (*(+*) )/ .1$.0$.D*(**/@ .D(+*.D /F
RTFSF ) -$5:9*+-$'
"-) 1)/" ( ( 0/$'$5- %3 ; +* - /0'$5- + ). *. *(+*) )/ .
) ..7-$*. ( 0( +7"$)F (*. 3 (+'$B- .. !0)$*)'$ *( 0( 3 (+'*
(0$/*.$(+' .D,0 +*..0$0((+* 0(*(+*) )/ .= / 3/*F
*..*()" )/ (0(/-$0/* nomeD*(. 0 --+ ,--+F
@Named
@RequestScoped
public class MeuBean {
private String nome;
public String getNome() {
return nome;
www.algaworks.com 171
}
public void setNome(String nome) {
this.nome = nome;
}
}
+7"$)
0. /" <f:ajax> +- $$*)- !0)$*)'$ %3 )*
*(+*) )/ <h:inputText>F
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>Teste Ajax</title>
</h:head>
<h:body>
<h:form id="frm">
<h:inputText value="#{meuBean.nome}">
<f:ajax render="ola" />
</h:inputText>
<br/>
<h:outputText value="Ol #{meuBean.nome}" id="ola" />
</h:form>
</h:body>
</html>
B)$(*. * $ N*'N +- * *(+*) )/ <h:outputText> ,0 $$*)(*.D
- ! - )$(*. .. ( .(*$)+-*+-$ render <f:ajax>F
<h:inputText value="#{meuBean.nome}">
<f:ajax render="ola" />
</h:inputText>
0)* !0)$*)'$ %3 ; $$*) ( 0( <h:inputText>D +*- +-9*D
0( - ,0$.$:9* %3 ; -$ )* 1 )/* (0): 1'*- L('!' MF * - /*-)*
.. - ,0$.$:9*D * *(+*) )/ .+ $B* ( render . -7 /0'$5*F - ./)/
+7"$)B*(* ./1D. (/0'$5:@ .F
www.algaworks.com 172
RTFTF +-*+-$ 1 )/
+-*+-$ event <f:ajax> .+ $B * 1 )/* ,0 -$-7 0( )*1 - ,0$.$:9*
%3F * .* 0( <h:inputText>D +* (*. 0.-D +*- 3 (+'*D changeD keyupD
mouseoverD focusD blurD click /F
0- (*. * 1 )/* ,0 $*)-7 0( )*1 - ,0$.$:9* %3 )*..* 3 (+'* +-
keyupF
<h:inputText value="#{meuBean.nome}">
<f:ajax event="keyup" render="ola" />
</h:inputText>
"*-D )*1 ' /- $"$/ )* (+*D 0( )*1 - ,0$.$:9* %3 ; $.+- *
*(+*) )/ N*'N/0'$5*F
RTFUF +-*+-$ '$./ ) -
+-*+-$ listener 1 . - $)!*-( *( 0( 3+- ..9* '$":9*
(;/**D ,0 . -7 3 0/* )* . -1$*- . (+- ,0 0( - ,0$.$:9* %3 !*-
$.+-F .. (;/** +* *0 )9* - - 0( -"0( )/* * /$+*
AjaxBehaviorEventF
www.algaworks.com 173
)'0$- (*. 0( (;/** transformar )* ()" )D ,0 . -7 #(* ).
- ,0$.$:@ .%3+-/-).!*-(-*)*( $"$/*+-' /-.($A.0'.F
public void transformar(AjaxBehaviorEvent event) {
this.nome = this.nome.toUpperCase();
}
"*-D!5 (*.- ! -<)$*(;/**0.)*
F
<h:inputText value="#{meuBean.nome}">
<f:ajax event="keyup" render="ola"
listener="#{meuBean.transformar}" />
</h:inputText>
)*1' /-$"$/)*(+*D*(;/** transformar . -7#(*F
RTFVF ) -$5:@ .(A'/$+'.
';( /-).!*-(- * )*( $"$/* +- ($A.0'*D * (;/** transformar
/(;( *)/-7 ,0)/*. -/ - . !*-( $"$/*. /-$0$-7 0( )*1 1-$71 '
$)./8)$D#( quantidadeCaracteresF
@Named
@RequestScoped
public class MeuBean {
private String nome;
private int quantidadeCaracteres;
public void transformar(AjaxBehaviorEvent event) {
this.nome = this.nome.toUpperCase();
this.quantidadeCaracteres = this.nome.length();
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public int getQuantidadeCaracteres() {
return quantidadeCaracteres;
}
}
www.algaworks.com 174
+7"$)
D $)'0=(*. 0( )*1* <h:outputText> +- 3$$- ,0)/$
-/ - .$"$/*.F
<h:inputText value="#{meuBean.nome}">
<f:ajax event="keyup" render="ola"
listener="#{meuBean.transformar}" />
</h:inputText>
<br/>
<h:outputText value="Ol #{meuBean.nome}" id="ola" />
<br/>
<h:outputText id="contador"
value="#{meuBean.quantidadeCaracteres} caracteres digitados" />
(*- *. -/ - . ./ %( . )* *)/*. + '* (;/** transformarD *
*(+*) )/ N*)/*-N)9*;/0'$5*H
* (*. .+ $B- ($. 0( *(+*) )/ ) +-*+-$ renderD . +-)* *.
$.+*- .+:*F
<h:inputText value="#{meuBean.nome}">
<f:ajax event="keyup" render="ola contador"
listener="#{meuBean.transformar}" />
</h:inputText>
* $"$/- 0( )*( D *. *$. *(+*) )/ . .9* /0'$5*. 0-)/ . - ,0$.$:@ . %3F
www.algaworks.com 175
RTFWF -* ..( )/*+-$'
- (*. '/ -- )*..* 3 (+'* +- $)$$- 0( - ,0$.$:9* %3 +-/$- 0( */9*D
#()*0((;/** :9**()" )F
(*. ,0- * >$"* * (;/** transformarD - (*1 )* * -"0( )/* * /$+*
AjaxBehaviorEventF
public void transformar() {
this.nome = this.nome.toUpperCase();
this.quantidadeCaracteres = this.nome.length();
}
* -,0$1* +7"$)D - (*1 (*. !0)$*)'$ %3 * <h:inputText>
$)'0=(*. (0()*1**/9*F
<h:inputText id="nome" value="#{meuBean.nome}" />
<br/>
<h:outputText value="Ol #{meuBean.nome}" id="ola" />
<br/>
<h:outputText id="contador"
value="#{meuBean.quantidadeCaracteres} caracteres digitados" />
<br/>
<h:commandButton value="Transformar" action="#{meuBean.transformar}">
<f:ajax render="ola contador" />
</h:commandButton>
0)* ..(*. +7"$)D $"$/(*. 0( )*( $*)(*. * */9*D 0( 3 :9*
NullPointerException ; '):D +*$. * /-$0/* nome ./7 )0'*H ( - ,0$.$:9* %3
./7. )*$.+-D(.**(+*) )/ <h:inputText> )9* ./7. )*+-* ..*F
*- +-9*D + ). * +->+-$* *(+*) )/ ,0 $$*)(*. !0)$*)'$ %3
; +-* ..* + '* 1 -1 - .F - $$*)- *0/-*. *(+*) )/ .D 0.(*.
+-*+-$ execute <f:ajax>D$)'0$)*. 0.$.F
<h:commandButton value="Transformar" action="#{meuBean.transformar}">
<f:ajax render="ola contador" execute="nome" />
</h:commandButton>
+7"$) !0)$*) "*-D $.+-)* - ,0$.$:@ . %3 +-/$- * '$,0 )* */9*
N-).!*-(-N +-* ..)**1'*-$"$/*)*(+* )/-F
www.algaworks.com 176
RTFXF '1-.G#1 +-- ) - 3 0/
,0$. -(*. /0'$5- *0 +-* ..- 0( "-0+* *(+*) )/ . ) +7"$)D +* (*.
0.-'"0(.+'1-.G#1 )*./-$0/*. render process <f:ajax>F
%/+=!/ ,+"76(
O'' **.*.*(+*) )/ .+7"$)
**.*.*(+*) )/ .*!*-(0'7-$*,0 +*..0$*
O!*-(
*(+*) )/ ,0 $.+-*0- ,0$.$:9*%3
O)*) )#0(*(+*) )/
O/#$. + ).**(+*) )/ ,0 $.+-*0- ,0$.$:9*%3
+ ). +- 3 (+'$B-D 1(*. '/ -- *)B"0-:9* %3 * */9*
N-).!*-(-ND+-0.-'"0(.+'1-.G#1 F
<h:commandButton value="Transformar" action="#{meuBean.transformar}">
<f:ajax render="@all" execute="@form" />
</h:commandButton>
www.algaworks.com 177
./ .*D * - *( )* . -$ )9* 0.- +'1-G#1 @all +- /0'$5- +7"$)
$)/ $-D %7 ,0 + ). /0'$5:9* *. (.-).-, ,0 +- $.(*. . -$ (0$/* ($.
-7+$F
RTFYF 7"$) ./-* '):( )/**(%3
- $$*)- %3 ) +7"$) ./-* '):( )/* * .$./ ( B)) $-*D
+- $.(*.+ ).0.-/" <f:ajax> )**/9*N'1-NF
<h:commandButton value="Salvar" action="#{cadastroLancamentoBean
.salvar}">
<f:ajax execute="@form" render="@form" />
</h:commandButton>
- $3- +7"$) 0( +*0* ($. $)/ -/$1 !$'$/- 1$ *. 0.07-$*.D
$$*)- (*. 0( )*1 !0)$*)'$ ) ./ +7"$)F 0)* * 0.07-$* $)!*-(-
/ 1 )$( )/* * '):( )/*D 0/*(/$( )/ D /-$0$- (*. /
+"( )/* *( ( .( / 1 )$( )/*F * 0.07-$* +- )# - /
+"( )/* )/ . / 1 )$( )/*D ) ./ .*D )9* $- (*. .0./$/0$- * ,0 %7 !*$
$)!*-(*F
(*. -$- 0( (;/** )* ) CadastroLancamentoBean +- /-/- * 1 )/*
(0): / 1 )$( )/*F
public void dataVencimentoAlterada(AjaxBehaviorEvent event) {
if (this.lancamento.getDataPagamento() == null) {
this.lancamento.setDataPagamento(this.lancamento
.getDataVencimento());
}
}
* (+* )/- / 1 )$( )/*D $$*)(*. <f:ajax> *( *. /-$0/*.
renderD execute listenerF
<h:outputLabel value="Data de vencimento" />
<h:inputText size="12" value="#{cadastroLancamentoBean.lancamento
.dataVencimento}" label="Data de vencimento">
<f:ajax render="@this dataPagamento"
execute="@this dataPagamento"
listener="#{cadastroLancamentoBean
.dataVencimentoAlterada}" />
<f:convertDateTime pattern="dd/MM/yyyy"
timeZone="America/Sao_Paulo" />
</h:inputText>
<h:outputLabel value="Data de pagamento" />
www.algaworks.com 178
<h:inputText size="12" value="#{cadastroLancamentoBean.lancamento
.dataPagamento}" label="Data de pagamento"
id="dataPagamento">
<f:convertDateTime pattern="dd/MM/yyyy"
timeZone="America/Sao_Paulo" />
</h:inputText>
www.algaworks.com 179
+=/0'*RU
-$( .
RUFRF
)/-*0:9*
-$( . ; 0( $'$*/ . *(+*) )/ . -$*. ( 1 -1 - .F .0=/
*(+*) )/ . $)'0$ $1 -.*. (+*. )/-D */@ .D / '. *.D 7-1*- .D
"-7B*.D$7'*"*.D /F
. *(+*) )/ . * -$( . +*..0 ( !0)$*)'$ %3 $)/ "-*D . *
)
%3 * F - *)# - /**. *. *(+*) )/ . $.+*)=1 $.D .. *
,!(0, ( #//+EJJ222F+-$( ! .F*-"J.#*2. JF
www.algaworks.com 180
RUFSF *)B"0-)**+-*% /*
$'$*/ -$( . ./7 $.+*)=1 ' +- *2)'* (
#//+EJJ222F+-$( ! .F*-"JF *(* ./(*. 0.)* 1 )D 1(*. + ). $$*)-
+ )<)$)*-,0$1* )(&61&% *+-*% /*F
<!-- PrimeFaces (biblioteca de componentes) -->
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>5.1</version>
<scope>compile</scope>
</dependency>
-*)/*H 9* +- $.(*. *)B"0-- ($. )F "*-D ; .> *( :- 0.- *.
*(+*) )/ .*-$( .F
RUFTF 0/+0/
'
)+0/ 3/
- 0.- *(+*) )/ . * -$( .D +- $.(*. $(+*-/- $'$*/
*(+*) )/ . ) +7"$)
F
- (*. '/ -- * -,0$1* ,-+('&'-(61!-&%
*.$./ (B)) $-*F
<!DOCTYPE html>
<ui:composition template="/WEB-INF/template/Layout.xhtml"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
.- (*.*$.*(+*) )/ .*-$( .E <p:outputLabel> <p:inputText>F
<p:outputLabel value="Descrio" for="descricao" />
<p:inputText id="descricao" size="60"
value="#{cadastroLancamentoBean.lancamento.descricao}" />
*(+*) )/ <p:outputLabel> ; 0( 3/ ).9* * *(+*) )/ ( .(* )*(
$'$*/ * F 0)* ..*$(*. .. *(+*) )/ 0( <p:inputText>D
)9* +- $.(*. .+ $B- * label )* (+* )/-D +*$. ; 0/*(/$( )/
/-$0=*F';($..*D --*. 1'$:9*'/ -(*-*/ 3/** %%F
*(+*) )/ <p:inputText> ; 0( 3/ ).9* * *(+*) )/ ( .(* )*(
$'$*/ * F (+* ; - ) -$5* *( 0( ,$"' $! - )/ * *(+*) )/
www.algaworks.com 181
+-9*F ';( $..*D ( .* --*. ..*$*. * *(+*) )/ D ' B ./*
+-*0.07-$*F
(&(1.-+/%"78,&%"'-=,">
. 1'$:@ . ) '$/$*) .9* 3 0/. )* '* * . -1$*-D (.
* -$( . / ( .0+*-/ 1'$:@ . '$ )/G.$ F .* / )# $)/ - .. (
*)# - *(* $..* !0)$*)D ..$./ 6 1= * 0' "-/0$/ )* '*"
'"*-&.F
#//+EJJ'*"F'"2*-&.F*(J1'$*G'$ )/G.$ G (G+-*% /*.G%.!G*(G
+-$( ! .J
RUFUF ' /) )0
*(+*) )/ <p:selectOneMenu> ; . * )* *(+*) )/ +-9* * D (.
$)'0$ ,$"''"' D.0+*-/ $:9*D ! $/*.DB'/-* *)/ A*0./*($5*F
www.algaworks.com 182
(0-(*. + ). * +- B3* h +- pD %7 ./- (*. 0.)* * *(+*) )/ *
-$( .F
<p:outputLabel value="Pessoa" for="pessoa" />
<p:selectOneMenu value="#{cadastroLancamentoBean.lancamento.pessoa}"
id="pessoa">
<f:selectItem itemLabel="Selecione" noSelectionOption="true" />
<f:selectItems value="#{cadastroLancamentoBean.pessoas}"
var="pessoa" itemValue="#{pessoa}"
itemLabel="#{pessoa.nome}" />
</p:selectOneMenu>
- #$'$/- !0)$*)'$ B'/-* * *(+*) )/ D ./ /-$0$- true 6
+-*+-$ filterF * (*. /(;( .*'# - !*-( ,0 ,0 - (*. B'/-- *.
' ( )/*. /-1;. filterMatchModeD ,0 $/ startsWithD containsD endsWith
customF
<p:outputLabel value="Pessoa" for="pessoa" />
<p:selectOneMenu value="#{cadastroLancamentoBean.lancamento.pessoa}"
id="pessoa" filter="true" filterMatchMode="contains">
<f:selectItem itemLabel="Selecione" noSelectionOption="true" />
<f:selectItems value="#{cadastroLancamentoBean.pessoas}"
var="pessoa" itemValue="#{pessoa}"
itemLabel="#{pessoa.nome}" />
</p:selectOneMenu>
(*.0(( )0 . ' :9*+-7/$* $)/0$/$1*H
RUFVF ' /) 0//*)
-$( . +*..0$ * *(+*) )/ <p:selectOneRadio>D ,0 ; . * )*
*(+*) )/ ( .(* )*( $'$*/ * F ( *0/-* *(+*) )/ ,0
www.algaworks.com 183
!0)$*) *(* 0( +"( ; * <p:selectOneButton>F .- (*. ' ) +7"$)
./-* '):( )/*.+-. ' :9**/$+**'):( )/*F
)/ . '/ -- +7"$)D 1(*. !5 - 0( + ,0 ) $(+' ( )/:9* )* )0(
TipoLancamentoD+-..*$-(*.0( .-$:9* 0.07-$*+-*)./)/ F
public enum TipoLancamento {
RECEITA("Receita"),
DESPESA("Despesa");
private String descricao;
TipoLancamento(String descricao) {
this.descricao = descricao;
}
public String getDescricao() {
return descricao;
}
}
"*-D $- (*. '/ -- * *(+*) )/ . ' :9* * /$+* '):( )/* +-
<p:selectOneButton>F
<p:outputLabel value="Tipo" for="tipo" />
<p:selectOneButton id="tipo"
value="#{cadastroLancamentoBean.lancamento.tipo}">
<f:selectItems value="#{cadastroLancamentoBean.tiposLancamentos}"
var="tipoLancamento" itemValue="#{tipoLancamento}"
itemLabel="#{tipoLancamento.descricao}" />
</p:selectOneButton>
%*- .0'/*E
www.algaworks.com 184
RUFWF ' )-
<p:calendar> ; 0( *(+*) )/ 0.* +- . ' $*)- /J#*-D *( .0+*-/
+"$):9*D'*'$5:9*D%3D /F
(*. '/ -- *. (+*. /. ) +7"$) ./-* '):( )/*. +- 0.-
./ *(+*) )/ F+-*+-$ pattern B) *!*-(/*/F
<p:outputLabel value="Data de vencimento" for="dataVencimento" />
<p:calendar id="dataVencimento" size="12" pattern="dd/MM/yyyy"
value="#{cadastroLancamentoBean.lancamento.dataVencimento}">
<p:ajax event="dateSelect" update="@this dataPagamento"
process="@this dataPagamento"
listener="#{cadastroLancamentoBean.dataVencimentoAlterada}" />
<p:ajax event="change" update="@this dataPagamento"
process="@this dataPagamento"
listener="#{cadastroLancamentoBean.dataVencimentoAlterada}" />
</p:calendar>
<p:outputLabel value="Data de pagamento" for="dataPagamento" />
<p:calendar size="12" id="dataPagamento" pattern="dd/MM/yyyy"
value="#{cadastroLancamentoBean.lancamento.dataPagamento}" />
./ 3 (+'*D 0.(*. /" <p:ajax> +- #$'$/- %3 +- * +-$( $-*
*(+*) )/ ' )7-$*F ./ /" ; 0( 3/ ).9* <f:ajax>D +-$)$+'
$! - ): ; ,0 /" * -$( . 0. %0 -4 +- !5 - - ,0$.$:@ . %3D ),0)/*
/" +-9* * 0. 0( $(+' ( )/:9* +->+-$F ';( $..*D /" <p:ajax> (0
*.)*( . '"0(.+-*+-$ .D*(*;*.* update processF
- (*. '/ -- * (+* .-$:9* '):( )/*D +- .0" -$- * 0.07-$* .
.-$:@ . %7 0.. L./-.M )/ -$*-( )/ F -$( $-( )/ D +- $.- (*. -$-
0()*1*(;/**)*- +*.$/>-$* LancamentosF
public List<String> descricoesQueContem(String descricao) {
TypedQuery<String> query = manager.createQuery(
"select distinct descricao from Lancamento "
+ "where upper(descricao) like upper(:descricao)",
String.class);
query.setParameter("descricao", "%" + descricao + "%");
return query.getResultList();
}
(;/** descricoesQueContem . ' $*) /*. . .-$:@ . $./$)/.
'):( )/*.DB'/-)*+*-0(+-/ .-$:9*F
* ) CadastroLancamentoBeanD $)'0$- (*. 0( (;/** ,0 . -7 0.* +-
+- )# -..0" ./@ .**(+*) )/ F
@Inject
private Lancamentos lancamentos;
public List<String> pesquisarDescricoes(String descricao) {
return this.lancamentos.descricoesQueContem(descricao);
}
+7"$) ./-*D ./ $)'0$-(*. * *(+*) )/ <p:autoComplete> ..*$-
*(;/** pesquisarDescricoesD/-1;.+-*+-$ completeMethodF
<p:outputLabel value="Descrio" for="descricao" />
<p:autoComplete id="descricao" size="60"
value="#{cadastroLancamentoBean.lancamento.descricao}"
completeMethod="#{cadastroLancamentoBean.pesquisarDescricoes}" />
"*- * (+* )/- .-$:9* * '):( )/* .0" - .-$:@ . *(+' /.
,0 !*-(0.. (*0/-*.'):( )/*.F
www.algaworks.com 186
RUFYF .." .
*(+*) )/ <p:messages> ; 0( 3/ ).9* * *(+*) )/ +-9* * D *( 0(
1$.0'($./- )/ .0+*-/ %3F
<h:form id="frm">
<p:messages showDetail="false" showSummary="true"
autoUpdate="true" />
...
</h:form>