Sunteți pe pagina 1din 47

Last modification: 05.10.

2012 - 1 -
ZK, Java and the World.
The Zksample2 project.
A demo application that shows the integration of the zk AJA we! framework with several
common "sed frameworks for data!ase access, middle ware, sec"rit# and reporting.
$pdated to zk v%.&.''
Zksample2 Help to prevent the global warming by writing cool software. http:www.forstha!s.de
Last modification: 05.10.2012 - 2 -
Ta!le of contents
1.About the Authors...............................................................................................................3
2.Preface...............................................................................................................................3
3.Update ZK libs from 3.6.3 to 5.x.......................................................................................3
3.1.Chanes in the Confiuration !for "# 5.$%&.................................................................%
3.2.Chanes in the Confiuration !for "# 5.$6&.................................................................5
3.3.Chanes in the Confiuration !for "# 5.$.'.1&.............................................................5
3.%.Chanes in the Confiuration !for "# 5.$.1$&..............................................................5
3.5.Chanes in the Confiuration !for "# 5.$.11&..............................................................5
%.Used frame(or#s...............................................................................................................5
5.Prere)uisites......................................................................................................................6
6.*o(nload and +nstall..........................................................................................................'
'.A little bit about ma,en.......................................................................................................-
-.An o,er,ie( about the tiers................................................................................................-
../he bac#end......................................................................................................................-
1$./he fronted........................................................................................................................
1$.1.0hat1s in a standard module !annotate databinded&..............................................1$
1$.2./he 2odule 2ainController....................................................................................1$
1$.3./he list (indo( !manual databinded in controller code&........................................11
1$.%./he dialo (indo(..................................................................................................15
1$.5.3eportin (ith *4namic5asper...............................................................................1'
11.6ocalisation....................................................................................................................1'
12./he confiuration files....................................................................................................1-
13.7prin.............................................................................................................................1.
13.1.7prin A8P.............................................................................................................2$
13.2.7prin97ecurit4.......................................................................................................2$
13.3.7ecurit49Concept....................................................................................................21
13.%.7prin :ean scopes................................................................................................22
13.5.An one9time9pass(ord implementation..................................................................23
1%.5unit testin....................................................................................................................25
15.;o( /o1s and special components.................................................................................25
15.1.;o( to build a custom constraint (ith a parameter...............................................25
15.2.;o( to declare a custom constraint (ith parameter in "uml .................................26
15.3./4peCon,erters......................................................................................................2'
15.%.;o( to o,erhand parameters to composers..........................................................2-
15.5.6on runnin operations < /he =cho =,ent...........................................................3$
15.6.2odal !7earch& *ialos that are ettin bac# an ob>ect.......................................31
15.'.=,ent?ueues. 0e are buildin a 7tatus:ar controller...........................................3%
15.-.=,ent?ueues. 0e are buildin a 2essae:ar controller.......................................36
15...*ashboard modules................................................................................................3-
16.A,oid common failures...................................................................................................%$
16.1.*ata:inder failures.................................................................................................%$
1'.;o( to replace the in2emor4 ;2 sample database......................................................%1
1-./he pac#ae structure..................................................................................................%2
1-.1.:ac#end..................................................................................................................%2
1-.2.@rontend..................................................................................................................%2
1-.3.;istor4 of chanes..................................................................................................%3
Zksample2 Help to prevent the global warming by writing cool software. http:www.forstha!s.de
Last modification: 05.10.2012 - 3 -
'. A!o"t the A"thors
*ipl.rer.pol. 7tephan Aerth is a reat fan of the ZK frame(or#. ;e1s the initiator of the
Z#sample pro>ect and a Z#oss forum contributor as 1/err4/ornado1.
+f 4ou need help b4 4our "# pro>ects (ith interatin sprin and hibernate 4ou can
hire him (orld(ide.
:>Brn :ruhns is a 5a,a de,eloper (ith about 15 4ears experience. ;e1s (or#in a
lon time in the enterprise en,ironment for bi automoti,e companies . :>Brn doin
most of the complex technical initial implementations of the sample pro>ect. ;is
Z#oss forum nic# is 1*aibutsu1.
2. (reface
/his documentation is a (or# in proress. +f someone (hishes more explanations about special details on
the pro>ect please feel free to as# us for it.
/he Z#sample2 application !further shortl4 named Z#sample2& is the continuation of (or# on our "#9sample9
ui application (hich is bein to de,elop as ZK releases his ,ersion 3.5.2 of it1s reat A5AC (eb frame(or#.
+t1s build no( (ith the ZK ,ersion 5.$.%. ZK is a e,ent9dri,en and component oriented (eb frame(or# (ritten
in 5a,a.
Dou can reach the online sample application at the start paeE httpEFF(((."#9(eb.deF"#sample2F
+t uses further a stac# of other frame(or#s for buildin a robust and scalable 52== =nterprise application.
Unli#e the first sample ,ersion (hich is build (ith Ant the Z#sample2 is build (ith 2a,en2. 7o the pro>ect
structure ha,e chaned and it1s therefore deplo4ed as a ne( pro>ect.
+n this documentation (e (ill onl4 pointed to interestin parts on it and hope that it (ill be useful for the
readers (ho (ants to build an enterprise (eb application (ith the ZK (eb frame(or# for the frontend.
7e,eral controllers are (or#in no( !since updated to "# 5.$.3& (ith automaticall4 Annotated *ata:indin.
). $pdate ZK li!s from ).*.) to %.+
/hese da4s (e ha,e "pdated the Z#sample2 pro>ect from ZK ,3.6.3 to ZK version %.&.,.
0e are e,aluatin the 5.x ,ersion natural for a loner timeG so (e (on1t not onl4 chane the libs but (e also
made sinificant modifications to the Z#sample2 codes that mirrors our experience (ith the ne( reat
,ersion.
0ith this ne( ,ersion (e ha,e modified se,eral of the modules to (or# no( (ith the automaticall4
Annotated -ata!inding mechanism of ZK. 7ome modules (ill be double because (e (ill sho( the (a4s for
manual databindin and the annotated databindin (a4 in code. @urther a best practice on ho( to share the
model and not the binderG because *ata:inderFAnnotate*ata:inder is not a "# componentG so 4ou (ill find
no +* for it. 0ith this mechanism annotated databindin (e can reduce dramaticall4 the .o/ !6ines of
Code&.
+n this case (e ha,e adapt our Paed6ist0rapper !Aolden Co( for *:97ortinF*:9PainFAeneratin ;?6
?ueriesF(ithout la"46oadin ;ibernate exception& for *atabindin too.
0ith the 5.x ,ersion comes some ne( thins for usG so (e (ould implement these thins step b4 step. 8ne
,er4 interestin ne( feature are the 0vent1"e"es class. Dou can imaine this as a lobal listener.
Zksample2 Help to prevent the global warming by writing cool software. http:www.forstha!s.de
Last modification: 05.10.2012 - % -
080 absolute interestin for a (eb application. 0e use this ne( feature for sho(in ho( to build a
7tatus:arController that can actuali"e his information from an4 place in code. 6ater (e (ill (rite a ne( chat
module (ith the =,ent?ueues mechanism.
3.1. Changes in the Configuration (for zk 5.04)
:ecause the e,ent9thread is disabled as default in 5.x for modal (indo(sG (e must first enable it. +1m not
aree that the application runs faster b4 disablin it. /he Aoal from A5AC frame(or#s is that the4 (ill brin
the des#top to the (eb. And for me a modal (indo( is exactl4 that (hat i1m a(ait. Au4s (ho mean that it
slo(do(n the app should order the next 16 core cpu on their ser,ers. /oda4 hard(are po(er is so cheap.
<!-- ========================================================== -->
<!-- Enable event thread for modal windows -->
<!-- ========================================================== -->
<system-config>
<disable-event-thread>false</disable-event-thread>
</system-config>
/he second modif4in in our zk.+ml is because of the situation that the default font9famil4 is chanedG so (e
(ill set it bac# to our (ell #no(n font and si"e.
<!-- ========================================================== -->
<!-- since 5.0.3 -->
<!-- he defa!lt font si"e is changed to #arial$ sans-serif# -->
<!-- %ere we set to the old settings -->
<!-- ========================================================== -->
<library-&ro&erty>
<name>org."'oss."!l.theme.font(amily</name>
<val!e>)erdana$ ahoma$ *rial$ %elvetica$ sans-serif</val!e>
</library-&ro&erty>
<library-&ro&erty>
<name>org."'oss."!l.theme.font(amily+</name>
<val!e>)erdana$ ahoma$ *rial$ %elvetica$ sans-serif</val!e>
</library-&ro&erty>
After updatin the "# libs (e see that some of the css definitions are chaned and the desin is not in our
sense. 7o it1s no( on da4 that (e spend an o(n css9file for the application instead do all the st4le
chanesFmodifications in all the "ul9files or the >a,a classes.
0e must declare our little css9file in the lang2addon.+ml
<stylesheet href="/css/zul/zksample2.css" ty&e="text/css" />
! (hich self is declared in the "#.xml file& file.
<!-- ========================================================== -->
<!-- ,ath to the character set and si"es -->
<!-- -'oss config!ration file -->
<!-- +!stom com&onents are declared here -->
<!-- ========================================================== -->
<lang!age-config>
<addon-!ri>/.E/-01(/lang-addon.2ml
</addon-!ri>
</lang!age-config>
Hext lines (ill enable that all user actions displa4s a (ait indicator.
<!-- ====================================================== -->
<!-- 3is&lays the wait indicator for every !ser action -->
<!-- ====================================================== -->
<library-&ro&erty>
<name>org."'oss."!l.&rogressbo2.&osition</name>
<val!e>center</val!e>
</library-&ro&erty>
<client-config>
<&rocessing-&rom&t-delay>4</&rocessing-&rom&t-delay>
</client-config>
Zksample2 Help to prevent the global warming by writing cool software. http:www.forstha!s.de
Last modification: 05.10.2012 - 5 -
3.2. Changes in the Configuration (for zk 5.06)
7ee chapter 3.3
3.3. Changes in the Configuration (for zk 5.0.7.1)
:4 exportin the pro>ect as a .(ar9file (e chec# if all is runnin. 7o (e see that the desin lac#s absolute.
7eems that there are the bac#round pics for the moldIJ3dJ are missin.
/he cause is that (e let buildin the application b4 ma,enG (e use params for the ,ersions of se,eral
frame(or#s that ma,en tr4 to load. 2eans (e do not (rite to all dependencies the 1real1 ,ersion either (e
use the ,ariables for it.
<de&endency>
<gro!&0d>org."'oss."'</gro!&0d>
<artifact0d>"'&l!s</artifact0d>
<version>56"'oss.version7</version>
</de&endency>
. . .
<&ro&erties>
<&ro8ect.b!ild.so!rceEncoding>9(-:</&ro8ect.b!ild.so!rceEncoding>
<"'osslibs>56basedir7/src/main/weba&&/.E/-01(/lib/</"'osslibs>
<s&ring.version>3.0.;.<E=E*>E</s&ring.version>
<s&ringsec!rity.version>3.0.;.<E=E*>E</s&ringsec!rity.version>
<"'oss.version>5.0.?.4</"'oss.version>
</&ro&erties>
0or#in in this la"4 (a4 o,ersee that in the do(nloaded "# frame(or# libs are a fe( files that must be
copied manuall4.
2a,en does not load the "# needed files that are be stored behind the 0=:9+H@ folder li#e the 0=:9
+H@FtldF(ebF... files. /hese "# ,ersion dependend files 4ou must cop4 manuall4 each time 4ou chane the "#
,ersion. 7o in our case (e ha,e un"ipped the complete "# ,ersion in a folder outside the pro>ect and cop4
the needed files.
3.4. Changes in the Configuration (for zk 5.0.10)
Ho modifications needed.
3.5. Changes in the Configuration (for zk 5.0.11)
Ho modifications needed.
,. $sed frameworks
ZK (eb frame(or# httpEFF(((."#oss.orF
used for the frontend as a component oriented and e,ent dri,en (eb frame(or#.
;ibernate 832 httpsEFF(((.hibernate.orF
used in the bac#end as 8b>ect 3elational 2apper bet(een /ables records and Po>os !*omain
2odels&
7prin httpEFF(((.sprinsource.orF
as a common =nterprise frame(or#. Used for the scopes of lifetime for the created controllers and
*A8s.
7prin A8P httpEFF(((.sprinsource.orF
A8P ! Aspect oriented prorammin & frame(or#G Used for our transaction scopes in the *A81s and
7er,ices.
Zksample2 Help to prevent the global warming by writing cool software. http:www.forstha!s.de
Last modification: 05.10.2012 - 6 -
7prin97ecurit4 httpEFF(((.sprinsource.orF
7ecurit4 frame(or#. Used for the authentication of a user and authori"ation for the components and
methods.
;ibernate9Aeneric9*A8 httpEFFcode.oole.comFpFhibernate9eneric9daoF
0e used onl4 pieces of this frame(or#. @rom it1s 7earch class it enerates the ;?6 ?ueries. +t1s the
basic of our paed lists that can be sorted on the database too.
5asper3eport httpEFF>asperfore.orF
Used for the printin of reports.
*4namic5asper httpEFFd4namic>asper.sourcefore.netF
Used for creatin d4namic 5asper reports at runtime. 2ost of our reports uses them.
@urther their are much more libs b4 dependenc4. /han#s for all of them.
%. (rere3"isites
/he Z#sample2 pro>ect is an =C6+P7= pro>ect and de,eloped under =clipse == 3.5 Aalileo and =clipse ==
3.% Aan4med.
=clipse +*=
2a,en2
/omcat
2a,en Pluin
7ub,ersion Pluin
*o(nload and install 2a,en2 from hereE httpEFFma,en.apache.orF
As a ma,en pro>ect 4ou need to do(nload and install the 2a,en9Pluin for =clipse. Dou can do(nload it from
httpEFFm2eclipse.sonat4pe.orF .
/he Z#sample2 is chec#ed in to a 7ub,ersion 3epositor4 to httpEFFsourcefore.netF .
7o 4ou must do(nload and install the 7ub,ersion Pluin for =clipse. Dou can do(nload it from
httpEFFsubclipse.tiris.orF .
@or runnin the application 4ou need a ser,let container. 0e recomended /omcat and refer to it (hen (e
(rite about the used confiuration files. Dou can do(nload it from httpEFFtomcat.apache.orF . 0e used in our
en,ironment the /omcat ,ersion 6.$.26.
After installin /omcat on 4our local machine 4ou must tell =clipse (here the installation is placed.
Zksample2 Help to prevent the global warming by writing cool software. http:www.forstha!s.de
Last modification: 05.10.2012 - ' -
*. -ownload and 4nstall
@or chec#in out the Z#sample2 pro>ect o to =clipse K0indo(LK8pen Perspecti,eLK8thersL and select
the entr4 17MH 3epositor4 =xplorin1 . Add a ne( 3epositor4 6ocation li#e in the picture belo(.
/he chec#out U36 isE httpsEFF"#sample2.s,n.sourcefore.netFs,nrootF"#sample2F
/he best (a4 is to imported all three sub pro>ects seperate. /he fourth pro>ect folder is the documentation .
After importin 4our pac#ae explorer should see li#e thisE
1. "#oss I (eb9frontend
2. sprin9hibernate9bac#end I bac#end.
3. Ke4AenZ#oss I /o#eni"er for eneratin a one9time9pass(ord (ith a little s(in client.
Zksample2 Help to prevent the global warming by writing cool software. http:www.forstha!s.de
Last modification: 05.10.2012 - - -
%. "#sample2Ndoc I /his document as an 8pen8ffice docO
Dou can run the application b4 oin to the "#oss pro>ect and riht clic# on the pro>ect name and select Krun
asL Krun on ser,erL
5. A little !it a!o"t maven
+n the first ,ersion of the sample application !called "#NsampleNui and hostet on code.oole.com (ith "#
3.6.3& (e exported the application as a (ar9file and upload it (ith the /omcat 2anaer to the ser,er. /he
upload speed (e ha,e is onl4 1%#bFs so it used about %$ minutes to deplo4 the application. /his (as ,er4
anr4. @urther is /omcat not de,eloped to ma#e a robust hot deplo4ment. 7o (e must first undeplo4 the
application and then upload it to be sure that e,er4thin (or#s o# after a ne(l4 deplo4ment other(ise often
(e ha,e do it t(o times E9! .
7o our 7ub,ersion 3epositor4 is on a (eb ser,erG it (ould be absolut fantastic to let the application build on it
and deplo4 the (ar9file from there.
/his is one mainl4 reason (h4 (e chaned the build tool. Ho( (e can start a script on the (eb ser,er that
tells ma,en (here are the pro>ects to chec#out and (hat to do (ith it.
A ne(l4 deplo4ment !chec#out on ser,erG compilinG (ar9inG deplo4in & needs under 1 minute.
7econdl4 (e ha,e a smaller pro>ect si"e in our 7ub,ersion pro>ect repositor4G because the needed libs are
do(nloaded and stored separate in the ma,en repositor4. 7o don1t be unpatience on first runnin the build of
the sample application because all sub pro>ects needs to do(nload se,eral libs for it.
Additionall4 (e ha,e in our build script on the ser,er a special instruction that do o,er(rite a fe(
confiuration files for the used *atabase from outside the pro>ects repositor4 so (e can build the pro>ect for
(or#in aainst the Postre7?6 *atabase on our (ebser,er. /he default datasource confiuration file in the
sample codes is (or#in aainst an +n2emor4 ;2 *atabase.
6. An overview a!o"t the tiers.
A tier means a la4er of similar ob>ects. /herefore multi9tier applications can ha,e multiple la4ers of similar
ob>ects. 7o in soft(are architecture pieces of the proram can be seperated in se,eral tiers. /hese tiers can
be on different places too.
/he most common #no(n multi9tier architecture is the 29tier or clientFser,er architecture (here one tier is the
database ser,er and the second tier is the ui client. A 39tier application ha,e 1. user interface F 2. business
loic F 3. database.
/he Z#sample2 ha,e % tiers.
1. User +nterface Ffrontend
2. Aui 7er,ices F 3eportin
3. /he :usiness 6oic
%. *atabase
7. The !ackend
/he bac#end do all the stuff that ha,e to do (ith the C3U* !/reate 8ead $pdate -elete& functions of an
application. 0e concentrate us on the main pac#ae structure that is as follo(sE
de.forsthaus.bac#end.dao ! +nterfaces for the -ata Access 9b>ects methods&
de.forsthaus.bac#end.dao.impl ! +mplementation of the +nterface methods &
de.forsthaus.bac#end.model ! *omain ob>ects also called Po>o1s &
de.forsthaus.bac#end.ser,ice ! +nterfaces for the 7er,ices &
Zksample2 Help to prevent the global warming by writing cool software. http:www.forstha!s.de
Last modification: 05.10.2012 - . -
de.forsthaus.bac#end.ser,ice.impl ! +mplementation of the +nterface methods &
/he *A8 classes are holdin all classes for the C3U* operations. =,er4 sinle *A8 class is standin for a
sinle table . Con,entions are ood thins for orientation. 7o (e named e,er4 *A8 li#e the correspondin
table name ad,anced (ith a 1*A81 li#eE
Interface = de.forsthaus.backend.dao.CustomerDAO.
Methods Implementation = de.forsthaus.backend.dao.impl.CustomerDAOImpl.
Ho( (e ha,e the C3U* operations for all the tables in their *A81s. ;mmmmmmG for (hat1s the hac# are the
7er,ices PPP
+n the case as (e defined that e,er4 table has one correspondin *A8 classG (e could sa4 that in such a
class the operation li#e an insert or delete (ill do it in a sinle transaction onl# for this table. /he action is
(ritten !commit& to the database or rolled bac# !rollbac#& (hen failed.
@or a operation that must (riten into more than one table (e (or# (ith 7er,ices. A ood example is here the
ban#in transfer. 2r. 6eft (ill ma#e a transfer of 1$$Q to his friend 2r. 3iht. 7o the ban# account from 2r.
6eft (ill decrease about 1$$Q and the ban# account from 2r. 3iht (ill increase about 1$$Q. ;ere are /08
different tables in (or# that (e (ould access in one 7er,ice. 0hat are happens (hen the ser,er crashes 4et
in the moment as 2r. 6eft1s account are decreased about 1$$Q and the +ncreasin cannot et (ritten to 2r.
3ihtPP
7o b4 definition a transaction must be AC+* Atomic F /onsitent F 4solated F -urable. 2eans if durin the t(o
operations on the different ban# accounts a failure arieses that all are rolled bac#. All must be 8K or nothin.
7o it1s a fine thin to set the transaction scope around the t(o operations as a sinle one. /herefore are the
7er,ices.
+n the sprin A8P section of this documentation 4ou1ll read (h4 4ou don1t find codes in the bac#end about
the transactions li#e the follo(in codesE
tr4 R
9serransaction t2 = ...
t2.begin@AB
// 3o some wor'
t2.commit@AB
7
catch @<!ntimeE2ce&tion eA 6
t2.rollbac'@AB
throw eB // or dis&lay error message
7
'&. The fronted
@or the frontend (e use the ZK frame(or#. @or more information o to their homepae on
httpEFF(((."#oss.orF .+n most cases (e do describin the modules li#e customers or uestboo# in a list and
a correspondin data dialo for insertin or editin the records.
:oth pieces are desined in the "ul9files and ha,e o(n controllers. 0hile in the first ,ersion of our sample
application onl4 the bac#end (as sprin manaed (e set the controllers in the "ul files (ith the
use=de.aFirm.aProg.aController attributG so the controllers extend the (indo( component. Ho( as the
frontend is sprin9manaed too (e set their controllers (ith the attribut appl#IJde.aFirm.aProg.aControllerJ
and extend all controllers from the Aeneric@or(ardComposer.
+n all cases (e ha,e onl4 9:0 (indo( container component in a sinle "ul9file and for a propper access (e
create A66 "ul9files and so their controllers (ith E2ec!tions.createComponents@my-!l(ile$
center$ nullA (here center is the Center area of the borderla4out in our mainpae index.zul B
Zksample2 Help to prevent the global warming by writing cool software. http:www.forstha!s.de
Last modification: 05.10.2012 - 1$ -
10.1. What's in a standard modue (annotate data!inded)
0e do ha,e a loo# on the branches module for explainin the construction of such a set of "ul9files and their
controllers. 0ith branch (e mean branch of industr4 i.e. electronicG foodG +/G automoti,eG insurance.
8ne of our con,ention is that a ui module ha,e normall4 three pac#aes. 8ne for the controllersG one for the
+tem3enderers or con,erters and one for the reports if the4 need such. 7o the pac#ae structure of the
branch is li#e thisE
de.forsthaus.(ebui.branch
:ranch2ainCtrl.>a,a
:ranch*ialoCtrl.>a,a
:ranch6istCtrl.>a,a
de.forsthaus.(ebui.branch.model
empt4E no special renderer for this case used
de.forsthaus.(ebui.branch.report
:ranch7imple*53eport.>a,a
/he "ul9templates (e ha,e stored in the folders under 0=:9+H@FpaesFJmoduleHamesJFS .
H=0OOO 7ince (e ha,e updated the Z#7ample2 to "# , 5.x in se,eral modules (e (or# (ith the Annotated
*atabindin mechanism. /he manual old (a4 (ith *atabindin in code comp.setMalue!bean.propert4& F
comp.etMalue!bean.propert4& and the second case (ith Annotated automaticall4 *atabindin. Dou can
disco,er the modules that are (or#in in the automaticall4 annotated data!inded (a4 on their suffix !adb& in
their menu texts.
+f (e need no special +tem3enderer (e declare all attributes in the "ul file. Additionall4 (e ha,e set an
con,erter for a special result in the listbox.
10.2. "he #odue #ainControer
0e ha,e tr4 se,eral (a4s to (or# (ith the automaticall4 Annotated *atabindin mechanism in the face of the
need to split a module in se,eral tabs for administrate the data. 7o (e ha,e become problems to share the
binder to all related tabsG (e o the (a4 to share the models of the tab controllers. And for a better and clean
access from all tabs (e hold all beans and collections in the module1s 2ainController.
All /absF/abs*ata are loadin on demandG means if some tabs are (or#in toether (e must ensure that all
of these tabs are loaded toether. 8ne of m4 lo,el4 methods for this are the i.e. Events.sendEent@new
Event@#on>elect#$ tab+!stomer*ddon4$ nullAAB method. 0ith it 4ou can forceFsimulate the call of
the correspondin e,entG if it1s declared in the code. HoteE /his does onl4 (or# if 4ou are in an =,ent.
+f (e ha,e a loo# on the codes in the "ul9file (e distinuish t(o ma>or *ata:indin :eans. /he
selected.ist4tem and a 1normal1 bean that1s propert4 is sho(in it1s detail ,alue in a textbox or decimalbox
or some of the other "# components.
/he third #ind of that are a 6ist for the 6istboxes model.
@or an interComposer Communication (e o,erhanded to each created data controller the mainController
and ,ice ,ersa. 7o controllerA ha,e acces to controller: b4 the (a4 to call the mainController.etController:.
0e do this in the mainController b4
// overhanded this controller self in the &aramCa&
final Ca&<>tring$ Db8ect> ma& = +ollections.sin!leton"ap@main+trl1ame$ main+trlAB
E
// call the "!l-file and &!t it on the tab.
E2ec!tions.createComponents@+ontroller/."!l$ &arent$ ma&AB
:4 creatin the Controller: (e read bac# the o,erhanded mainController and et them the Controller:.
/FF
F 4. Get the overhanded Cain+ontroller.<br>
Zksample2 Help to prevent the global warming by writing cool software. http:www.forstha!s.de
Last modification: 05.10.2012 - 11 -
F ;. >et this controller in the Cain+ontroller.<br>
F 3. +hec' if a HselectedDb8ectH e2ists yet in the Cain+ontroller.<br>
F/
if @arg.containsIey@#Cod!leCain+ontroller#AA 6
set/ranchCain+trl@@/ranchCain+trlA arg.get@#Cod!leCain+ontroller#AAB
// >E %0> +D1<D==E< D %E Cain+ontroller
get/ranchCain+trl@A.set/ranch=ist+trl@thisAB
. . .
7
7o in fact the main2odule "ul9file is onl4 a small file (ith a (indo( component as a container (ith the
applied controller. A fe( /abs and the correspondin /abPanels. /hat1s all.
10.3. "he ist $indo$ (manua data!inded in %ontroer %ode)
0e bein (ith the "ul9template for the branches list named as branch6ist."ul. Dou1ll find them in the folder
0=:9+H@FpaesFbranchFbranch6ist."ul .
fileJ branch=ist."!l
<K2ml version="#.$" encoding="%&'()" K>
<!-- LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL -->
<!-- his taglib is !sed for the translations. -->
<!-- title=#56cJl@H&anelM/ranch=ist.titleHA7# -->
<!-- 0tHs the aN!ivalent to 8avaJ =abels.get=abel@#22#AB -->
<!-- LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL -->
<Ktaglib !ri=#htt&J//www."'oss.org/ds&/web/core# &refi2=#c#K>
<!-- LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL -->
<!-- <esolver class that allows >&ring to instantiated -->
<!-- the controller class for this "!l-file. .or's on -->
<!-- a&&ly=#56branch=ist+trl7# -->
<!-- LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL -->
<Kvariable-resolver class=#org."'oss."'&l!s.s&ring.3elegating)ariable<esolver#K>
<"' 2mlns="http*//+++.zkoss.or!/2$$,/zul"
2mlnsJh="http*//+++.+-.or!/#.../xhtml"
2mlnsJ2si="http*//+++.+-.or!/2$$#//"01chema(instance"
2siJschema=ocation="http*//+++.zkoss.or!/2$$,/zul http*//+++.zkoss.or!/2$$,/zul/zul.xsd">
<!-- LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL -->
<!-- .indow com&onent as container for other com&onents. -->
<!-- LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL -->
<window id="+indo+23ranches0ist" a&&ly="45branch0istCtrl6"
border="none" width="#$$7">
<!-- LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL -->
<!-- >et the %C= /D3O for D1=O this "!l file. -->
<!-- LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL -->
<style>
body 6 &addingJ 0 0B /F 0 &adding on to& and bottom and 0
&adding on right and left F/ 7
</style>
<&anel id="panel23ranch0ist"
title="45c*l89panel23ranch0ist.title9:6" border="none" />
<toolbar>
<b!tton id="btn;elp" image="/ima!es/icons/li!ht2#<x#<.!if"
toolti&te2t="45c*l89btn;elp.tooltiptext9:6" />
<b!tton id="button23ranch0ist2=e+3ranch"
image="/ima!es/icons/btn2ne+22#<x#<.!if"
toolti&te2t="45c*l89button23ranch0ist2=e+3ranch.tooltiptext9:6" />
<b!tton id="button23ranch0ist2>rint3ranches"
image="/ima!es/icons/btn2print22#<x#<.!if"
toolti&te2t="45c*l89button23ranch0ist2>rint3ranches.tooltiptext9:6" />
</toolbar>
<hbo2 style="paddin!* -px">
<s&ace />
<chec'bo2 id="checkbox23ranch21ho+All"
label="45c*l89checkbox23ranch21ho+All.label9:6" />
<se&arator bar="true" orient="ertical" />
<label id="lbl23ranch2Description"
val!e="45c*l89lbl23ranch2Description.alue9:6" />
<te2tbo2 id="tb23ranch2=ame" width="#2$px" />
<b!tton id="button23ranch0ist21earch23ranch=ame"
image="/ima!es/icons/search.!if"
label="45c*l89button23ranch0ist21earch23ranch=ame.label9:6"
toolti&te2t="4
Zksample2 Help to prevent the global warming by writing cool software. http:www.forstha!s.de
Last modification: 05.10.2012 - 12 -
5c*l89button23ranch0ist21earch23ranch=ame.tooltiptext9:6" />
<se&arator bar="true" orient="ertical" />
<label id="lbl23ranch2=o"
val!e="45c*l89lbl23ranch2=o.alue9:6" />
<te2tbo2 id="tb23ranch2=o" width="#2$px" />
<b!tton id="button23ranch0ist21earch23ranch=o"
image="/ima!es/icons/search.!if"
label="45c*l89button23ranch0ist21earch23ranch=o.label9:6"
toolti&te2t="45c*l89button23ranch0ist21earch23ranch=o.tooltiptext9:6" />
<se&arator bar="true" orient="ertical" />
</hbo2>
<borderlayo!t id="border0a?out2branch0ist">
<north border="none" height="2<px">
<&aging id="pa!in!23ranch0ist" &age>i"e="2$" />
</north>
<center border="normal">
<listbo2 id="list3ox3ranch" vfle2="true"
toolti&te2t="45c*l89listbox.tooltiptext9:6" width="...,7"
height="#$$7" m!lti&le="false">
<listhead si"able="true">
<listheader id="listheader23ranch2Description"
image="/ima!es/icons/se@uence.!if"
label="45c*l89listheader23ranch2Description.label9:6"
sort="auto" width="2,7" />
<listheader id="listheader23ranch2=o"
image="/ima!es/icons/builder.!if"
label="45c*l89listheader23ranch2=o.label9:6"
sort="auto" width="2$7" />
</listhead>
</listbo2>
</center>
<so!th border="none">
<se&arator />
</so!th>
</borderlayo!t>
</window>
</"'>
+f rendered it loo#s li#e thisE
/he tab 4ou are seen are created and named in the menu controller. /hat tab are appended for the
branch6ist."ul (ith the =xecutions.createComponents!& methode.
8,er the time (e ha,e build some special base controller classes from (hich (e extend our module
controllers. @or the sprin9manaed controllers that (e use in all of our ui modules (e ha,e one for the list
controllers !A@C:ase6istCtrl& and one for the dialo controllers !A@C:aseCtrl&. 8n top of these inheritance
is the ZK Aeneric@or(ardComposer that do the (irein and for(ardin per namein con,ention.
Aeneric@or(ardComposer
T A@C:aseCtrl
T A@C:ase6istCtrl
Zksample2 Help to prevent the global warming by writing cool software. http:www.forstha!s.de
Last modification: 05.10.2012 - 13 -
&!blic class /ranch=ist+trl e2tends G(+/ase=ist+trl</ranche> im&lements
>eriali"able 6
/his Composer allo( us to concentrate on the loic of the e,ents. /hrouh the namin con,ention (e ha,e
access to a component b4 its name and their e,ents. 0e access our (indo( container Ub4 its +* that (e
ha,e declared in the "ul file as 1windowM/ranches=istH. /he e,ent that (e (ill fill first (ith life is the
1on+reateH e,ent.
7o (e must named the public method on+reate$windowM/ranches=ist@Event eventA
+n this #ind of method !onCreateQa6ist0indo(Controller& of a list controller (e do all time the same stuff.
Chec# the rihts for the components.
Calculate ho( man4 ro(s ha,e place in the listbox.
Assin the @ieldComparators fields for the listheaders sortin.
@ill the 6istbox (ith a list2odel6ist. !0e use therefore a so called 7earch8b>ect from the ;ibernate9
Aeneric9*A8 frame(or# (hich is (rapped (ith our Paed6ist0rapper. /he 7earchob>ect holds the
Properties that (e use for the ?uer4 and enerates a ;?6 ?uer4 from that. 7o (e can pain AH*
sortin on the database (ith ease because the ?uer4 propert4 for the 7ort8rder is accordinl4
chaned b4 the on7ort=,ents of the 6ist;eaders. &
7et the +tem3enderer for the list:ox.
/he +tem3enderer class is named /ranch=istCodel0tem<enderer.
:ecause (e ha,e put the +tem3enderer in a seperate class and (e (ould do some e,ents on the 6ist+temsG
so (e must for(ard these e,ents to the controller class.
+n the render!& method on the end of the code is a lineE
+om&onents+trl.appl?'or+ard@item$ #on3o!ble+lic'=on3o!ble+lic'ed#AB
/his code do for(ardin the e,ent 1on*oubleClic#1 of the 1item1 in this case a 6ist+tem to a self named
method. 0e ha,e named it 1on*oubleClic#ed1. /hese method !read about the a,ailable e,ents of an 6ist+tem
in the "# docs& 4ou can reach no( in the listController b4 double clic# a listitem in the listbox.
@or readin the data from the item don1t foret to cast it to the riht ob>ect.
public void on3o!ble+lic'ed@Event eventA throws E2ce&tion 6
// get the selected ob8ect
=istitem item = list/o2/ranch.get>elected0tem@AB
if @item != nullA 6
// +*> D %E >E=E+E3 D/PE+
/ranche a/ranche = @/rancheA item.get*ttrib!te@#data#AB
...
/he dialo0indo( for insertin oder editin data can be called (ith a doubleClic# on such a 6istitem in the
listbox or b4 onClic# of the 1ne(1 button.
0e open such a dialo (indo( e,er4 time (ith the same loic. 0e select a ro( in the list b4 one of these
e,entsE onClic#G on*oubleClic# or on7elect (hich 4ou can see implemented in the article or uestboo# list
controller. +f (e (ould opened the dialo (ith a ne( empt4 entr4 (e ta#e the same open method
sho(*etailMie(!:ranche a:ranche& (ith a ne( empt4 ob>ect as parameter.
/FF
F D&ens the detail view. <br>
F Dverhanded some &arams in a ma& if needed. <br>
F
F @param a/ranche
F @throws E2ce&tion
F/
private void show3etail)iew@/ranche a/rancheA throws E2ce&tion 6
/F
F .e can call o!r 3ialog "!l-file with &arameters. >o we can call them
F with a ob8ect of the selected item. (or handed over these &arameter
F only a Ca& is acce&ted. >o we &!t the ob8ect in a %ashCa&.
F/
Zksample2 Help to prevent the global warming by writing cool software. http:www.forstha!s.de
Last modification: 05.10.2012 - 1% -
%ashCa&<>tring$ Db8ect> ma& = new %ashCa&<>tring$ Db8ect>@AB
ma&.&!t@#branche#$ a/rancheAB
/F
F we can additionally handed over the list/o2$ so we have in the dialog
F access to the listbo2 =istmodel. his is fine for synchroni"ing the
F data in the c!stomer=istbo2 from the dialog when we do a delete$ edit
F or insert a c!stomer.
F/
ma&.&!t@#lb/ranch#$ list/o2/ranchAB
// call the "!l-file with the &arameters &ac'ed in a ma&
try 6
E2ec!tions.createComponents@#/.E/-01(/&ages/branch/branch3ialog."!l#$ null$ ma&AB
7 catch @E2ce&tion eA 6
lo!!er.error@#onD&en.indowJJ error o&ening window / # L e.getCessage@AAB
// >how a error bo2
>tring msg = e.getCessage@AB
>tring title = =abels.!et0abel@#messageMError#AB
C!lti=ineCessage/o2.do1et&emplate@AB
C!lti=ineCessage/o2.sho+@msg$ title$ C!lti=ineCessage/o2.OA$ #E<<D<#$ trueAB
7
7
+n the dialo (indo( controller (e must no( read bac# the params in the o,erhanded map.
0e ha,e to search methods implemented. 8ne for the branch number and one for the branch text (here
onl4 a fe( sin must be e)ual. +t (or#s (ith the 1li#e1 operator in the s)l statement.
@or such a list or search methode (e (or# (ith the 7earch 8b>ect from the ;ibernate9Aeneric9*A8
frame(or#. +t1s an ob>ect that holds all stuff for eneratin a h)l !;ibernate 1uer4 .anuae& ?uer4. /he
entit4 !domain ob>ect& are appended for so called 1@ilters1 that are the a)ui,alent to the s)l 1(here clause1.
@etches are oin deeper and resol,es the relations to related tables.
/FF
F (ilter the branch list with Hli'e branch nameH. <br>
F/
public void on+lic'5b!ttonM/ranch=istM>earchM/ranch1ame@Event eventA throws E2ce&tion 6
if @lo!!er.is3eb!gEnabled@AA 6
lo!!er.deb!g@#--> # L event.to>tring@AAB
7
// if not em&ty
if @!tbM/ranchM1ame.get)al!e@A.isEm&ty@AA 6
chec'bo2M/ranchM>how*ll.set+hec'ed@falseAB // !n+hec'
tbM/ranchM1o.set)al!e@##AB // clear
// LL create the searchDb8ect and init sorting LL//
%ibernate>earchDb8ect</ranche> searchDb8/ranch =
new %ibernate>earchDb8ect</ranche>@/ranche.class$ co!nt<owsAB
searchDb8/ranch.add(ilter@new (ilter@#bra/e"eichn!ng#$ #Q# L tbM/ranchM1ame.get)al!e@A
L #Q#$ (ilter.O>2I0IAEAAB
searchDb8/ranch.add>ort@#bra/e"eichn!ng#$ falseAB
get,aged=ist.ra&&er@A.set>earchDb8ect@searchDb8/ranchAB
7
7
7o in this sample application (e load onl4 the data that (e need and this in a sinle call. 0e do not (or#
(ith 8pen7ession+nMie(@ilters. @or 2asterF*etail lists li#e our order list module that sho(s the order as
master and order positions as detailsG (e load the details b4 the onClic#!& or on7elect!& e,ent from the
master list.
T4(E +nitialisin of such masterFdetail ! li#e in the order list moduleE on+reate5order=ist.indow & lists
that are selected and filled after the pae is created does not (or# (ith simulatin a selection of a 6istitem in
the master listbox because at this time the components are not rendered. +n such a case do the selection on
the modelE
// init the first entry
=istCodel=ist lml = @=istCodel=istA list/o2Drder.getCodel@AB
// 1ow we wo!ld show the corres&onding detail list of the first
// selected entry of the C*>E< able
// .e became not the first item (<DC the list beca!se itHs not
// rendered at this time.
// >o we ta'e the first entry in the =istCodel=ist and set as
// selected.
if @lml.get>i"e@A > 0A 6
Zksample2 Help to prevent the global warming by writing cool software. http:www.forstha!s.de
Last modification: 05.10.2012 - 15 -
int row0nde2 = 0B
list/o2Drder.set>elected0nde2@row0nde2AB
// get the first entry and cast them to the needed ob8ect
Drder anDrder = @DrderA lml.get@row0nde2AB
if @anDrder != nullA 6
// get the related order &ositions
...
10.4. "he diaog $indo$
/he "ul9template for the branches dialo named as branch*ialo."ul. Dou1ll find them in the folder 0=:9
+H@FpaesFbranchFbranch*ialo."ul .
fileJ branch3ialog."!l
<K2ml version="#.$" encoding="%&'()"K>
<!-- LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL -->
<!-- his taglib is !sed for the translations. -->
<!-- title=#56cJl@H&anelM/ranch=ist.titleHA7# -->
<!-- 0tHs the aN!ivalent to 8avaJ =abels.get=abel@#22#AB -->
<!-- LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL -->
<Ktaglib !ri=#htt&J//www."'oss.org/ds&/web/core# &refi2=#c#K>
<!-- LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL -->
<!-- <esolver class that allows >&ring to instantiated -->
<!-- the controller class for this "!l-file. .or's on -->
<!-- a&&ly=#56branch=ist+trl7# -->
<!-- LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL -->
<Kvariable-resolver class=#org."'oss."'&l!s.s&ring.3elegating)ariable<esolver#K>
<"' 2mlns="http*//+++.zkoss.or!/2$$,/zul"
2mlnsJh="http*//+++.+-.or!/#.../xhtml"
2mlnsJ2si="http*//+++.+-.or!/2$$#//"01chema(instance"
2mlnsJa="http*//+++.zkoss.or!/2$$,/zk/annotation"
2siJschema=ocation="http*//+++.zkoss.or!/2$$,/zul http*//+++.zkoss.or!/2$$,/zul/zul.xsd">
<!-- LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL -->
<!-- .indow com&onent as container for other com&onents. -->
<!-- LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL -->
<window id="+indo+23ranchesDialo!"
title="45c*l89+indo+23ranchesDialo!.title9:6" border="none"
a&&ly="45branchDialo!Ctrl6" closable="true" width="B,$px"
height="2,$px">
<!-- LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL -->
<!-- >et the %C= /D3O style for D1=O this "!l file. -->
<!-- LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL -->
<style>
body 6 &addingJ 0 0B /F 0 &adding on to& and bottom and 0
&adding on right and left F/ 7
</style>
<borderlayo!t id="borderla?out3ranchDialo!">
<north border="none" margins="$C$C$C$">
<grid>
<col!mns si"able="true" height="2$px">
<!-- %el& /!tton -->
<col!mn width="B$px" align="left">
<hbo2>
<b!tton id="btn;elp"
image="/ima!es/icons/li!ht2#<x#<.!if"
toolti&te2t="4c*l89btn;elp.tooltiptext9:6" />
</hbo2>
</col!mn>
<!-- *ddtionally /!ttons -->
<col!mn align="center">
<hbo2>
</hbo2>
</col!mn>
<!-- +<93 /!ttons -->
<col!mn align="ri!ht">
<hbo2 s&acing=",px" style="paddin!*#px"
align="end">
<b!tton id="btn=e+" height="2$"
toolti&te2t="45c*l89btn=e+.tooltiptext9:6" />
<b!tton id="btnEdit" height="2$"
toolti&te2t="45c*l89btnEdit.tooltiptext9:6" />
<b!tton id="btnDelete" height="2$"
Zksample2 Help to prevent the global warming by writing cool software. http:www.forstha!s.de
Last modification: 05.10.2012 - 16 -
toolti&te2t="45c*l89btnDelete.tooltiptext9:6"/>
<b!tton id="btn1ae" height="2$"
toolti&te2t="45c*l89btn1ae.tooltiptext9:6" />
<b!tton id="btnClose" height="2$"
toolti&te2t="45c*l89btnClose.tooltiptext9:6" />
</hbo2>
</col!mn>
</col!mns>
</grid>
</north>
<center border="none" margins="$C$C$C$">
<div id="diCenter3ranch">
<&anel id="panel23ranch"
title="45c*l89panel23ranch.title9:6" style="mar!in(bottom*#$px"
border="normal">
<&anelchildren>
<grid fi2ed=ayo!t="true"
style="border*$px">
<col!mns>
<col!mn width="#,$px" />
<col!mn width="#$$7" />
</col!mns>
<rows>
<row>
<label id="label23ranch23ra=r"
val!e="45c*l89label23ranch23ra=r.alue9:6" />
<te2tbo2 id="bra=r"
width="#$$px" />
</row>
<row>
<se&arator bar="true"></se&arator>
<se&arator bar="true"></se&arator>
</row>
<row>
<label
id="label23ranch23ra3ezeichnun!"
val!e="4
5c*l89label23ranch23ra3ezeichnun!.alue9:6" />
<te2tbo2 id="bra3ezeichnun!"
width="#$$7" />
</row>
</rows>
</grid>
</&anelchildren>
</&anel>
</div>
</center>
</borderlayo!t>
</window>
</"'>
+f rendered it loo#s li#e thisE
All components that (e must access b4 code become an o(n uni)ue 1spee#in1 idenitifier.
0e access our (indo( container Ub4 its +* that (e ha,e declared in the "ul file as
1windowM/ranches3ialogH. /he e,ent that (e (ill fill first (ith life is the 1on+reateH e,ent.
7o (e must named the public method on+reate5windowM/ranches3ialog@Event eventA
+n this #ind of method !onCreateQa*ialo0indo(Controller& of a dialo controller (e do all time the same
stuff.
Zksample2 Help to prevent the global warming by writing cool software. http:www.forstha!s.de
Last modification: 05.10.2012 - 1' -
Chec# the rihts for the components.
Create the button controller for the C3U* buttons.
Aet the params that (e o,erhanded b4 creation.
7et field properties.
7ho( the dialo in a modal (a4.
/he do>how3ialog@/ranche a/rancheA chec#s first the parameter a:ranche and et a ne( ob>ect for
it from the bac#end if it are null. Hext (e set the ,isible C3U* buttons for this initialisin of a ne( ob>ect or a
existin ob>ect for editin. /han (e set correspondentl4 a readonl4 or edit modus of the components. Hext
(e fill the components (ith the data and remember the initial ,alues for such a case that (e must set it bac#.
DesG that1s mainl4 all.
0e catch the onClose (indo( e,ent to a method called 1doClose!&1. /he same (e do for the onClic# e,ent of
our close button in the C3U* buttons section. +n it (e chec# if their are unsa,ed data. +f it so than (e as# the
user for sa,in the data.
10.5. &e'orting $ith ()nami%*as'er
:4 upradin the "#sample2 to the "# 5.$.3 ,ersion (e (ant to do also much of the missin reports. + see a
thread in the "# forum about *4namic5asper and spend the time to ha,e a loo# on their (ebsite. +t loo#s
interestin and so (e et itG actuali"e the ma,en dependencies and are ,er4 impressed about the eas4 and
fast (a4 to create reports on the fl4.
2ore about it comin soon...
''. .ocalisation
@or all components that (e use for sho(in text on the screen (e do add their identifier !+*& (ith the
components propert4 that (e use as the #e4(ord for translation in the lanuae propert4 files.
<label id="label23ranch23ra3ezeichnun!"
val!e="4{c:l(la!el"#ranch"#ra#ezeichnung.$alue%&
File: /WEB-INF/i3-label.properties
...
labelM/ranchM/ra/e"eichn!ng.val!e=descri&tion
&anelM/ranch=ist.title=/ r a n c h e s
...
File: /WEB-INF/i3-label_de_DE.properties
...
labelM/ranchM/ra/e"eichn!ng.val!e=/e"eichn!ng
&anelM/ranch=ist.title=/ r a n c h e n
...
At time (e use a default propert4 file for enlish and a propert4 file for the erman lanuae. 0e ha,e a section
in these files for the date and time formattin.
R ===========================
R 3ate and ime formats S
R ===========================
Zksample2 Help to prevent the global warming by writing cool software. http:www.forstha!s.de
Last modification: 05.10.2012 - 1- -
format.date=CC/dd/yyyy
format.time=hJmm a
format.timelong=hJmmJss a
format.datetime=CC/dd/yyyy hJmm a
format.datetimelong=CC/dd/yyyy hJmmJss a
+f needed (e format a date (ith a helper class de.forsthaus.(ebui.util.@**ate@ormat.>a,a that access the
propert4 files (ith a fe( options.
/FF
F (ormat the date/time. <br>
F
F @return >tring of date/time
F/
private >tring get3ateime@3ate dateA 6
if @date != nullA 6
return (33ate(ormat.!etDate&ime0on!'ormater@A.format@dateAB
7
return ##B
7
T4(E +f 4ou ha,e problems (ith the sho(n character set than ha,e a loo# at 4our eclipse ide. :e sure that
these files are sa,ed as U/@9-.
=clipse 9L Preferences 9L Content /4pes 9L 5a,a Properties @ile chane -efa"lt encoding to U/@9- .
'2. The config"ration files
@or such an application that (or#s (ith se,eral technics and frame(or#s (e need se,eral confiuration files
more for seperatin the essentials. +n this chapter (e (ill (rite a little bit of it and (here the4 can be found.
Please ha,e a loo# inside these files to see the comments in it.
we!.+ml !"#ossFsrcFmainF(ebappF0=:9+H@F(eb.xml&
7prin97ecurit4 =ntr4 point. 8nl4 settin a reference to the so called sprin 1securit49chain1.
7ettin location of the other confiuration files.
ZK (eb confiuration.
2iscellaneous for the ser,let enine.
zk.+ml !"#ossFsrcFmainF(ebappF0=:9+H@F"#.xml&
*efine the factor4 class for allo(in clusterin of the application.
*efine the class for monitorin the statistics.
*efine the path to the lan9addon.xml file.
*e,ice confiurations li#e t4pe of ser,er pushG timeout pae.
*efine max9des#tops per session.
74nchroni"e /hread6ocal ,ariables aainst the sprin frame(or#.
*efine the default font9famil4.
*efine the proressbox position.
lang2addon.+ml !"#ossFsrcFmainF(ebappF0=:9+H@Flan9addon.xml&
*efine font si"e.
*efine properties of commonl4 used components.
*efine the place of a used css9file.
application/onte+t2d!.+ml !"#ossFsrcFmainFresourcesFapplicationContext9db.xml&
Zksample2 Help to prevent the global warming by writing cool software. http:www.forstha!s.de
Last modification: 05.10.2012 - 1. -
*efinition of the transaction scopes for the *A8s and 7er,ices.
*efinition of the transaction manaer.
application/onte+t2g"iservices.+ml !"#ossFsrcFmainFresourcesFapplicationContext9uiser,ices.xml&
:ean definition of the ui ser,ices.
application/onte+t2zkoss.+ml !"#ossFsrcFmainFresourcesFapplicationContext9"#oss.xml&
:ean definition of the ui controllers.
application/onte+t.+ml !"#ossFsrcFmainFresourcesFapplicationContext.xml&
=mpt4. Hot used at time.
c"stomize2application/onte+t.+ml !"#ossFsrcFmainFresourcesFcutomi"e9applicationContext.+ml&
*efinition of the database connection and the primar4 #e4 manaer.
! /hese file is replaced (ith a read4 prepared postre7?6 definition outside the 7ub,ersion
repositor4 (hen (e build the online "#sample2 application and deplo4 them to the (eb& .
jd!c.properties !"#ossFsrcFmainFresourcesF>dbc.properties&
9 ;olds the >dbc.url username and pass(ord of the database (hen the application is confiured to
connect aainst a >dbc datasource.
mainmen".+ml !"#ossFsrcFmainFresourcesFmainmenu.xml&
9 ;olds the menu structure. +*1sG deepthG iconsG rihts and "ul9file names. /his file is parsed in our
menu@actor4 for buildin the menu as a tree2enu or bar2enu.
spring<ec"rit#/onte+t.+ml !"#ossFsrcFmainFresourcesFsprin7ecurit4Context.xml&
9 common confiuration of the sprin securit4.
application/onte+t2hi!ernate.+ml !sprin9hibernate9bac#endFsrcFmainFresourcesFapplicationContext9
hibernate.xml&
;olds the mappin resources.
common confiuration of the bac#end *A8 and 7er,ice beans.
'). <pring
+n the frontend (e use the 7prin @rame(or# for let them create the ui controllers and i,e them a scope of
the creation and the lifetime. 0e do not use a :ean@actor4 for creatin the beans. 0e (or# the common
(a4 (ith an ApplicationContextG so all beans are pre initiali"ed b4 creatin the contextG means b4 application
startup in the ser,let container. /hese (a4 of initiali"in needs a bit more time at startup but at runtime the
needed beans are much faster created as b4 (or#in in a the (a4 (ith VAuto(iredG means let sprin search
at runtime the needed classes. +n the applications bac#end sprin creates the *A8s and the 7er,ices.
0e scoped all beans as protot4pe. /his is the common (a4 for a multi9threaded (eb application and a
important point for a scalable application. 2eans that it must be secured that the application runs in a multi9
user mode and no user can modif4 other users ob>ects or data.
Zksample2 Help to prevent the global warming by writing cool software. http:www.forstha!s.de
Last modification: 05.10.2012 - 2$ -
@urther (e pre,er the scope protot4pe for the AU+ controllers too instead of session. 7o (e can be sure that
(e et no old stuff if (e call a ui controller se,eral times.
T4(E A,oid the use of static ,ariables in a multi9user (eb application because this ,ariable is onl4 8H= time
declared in the (hole application and the lifetime of such a ,ar is from the beinin of the (eb application
and ends if the application is stopped on the ser,er. 7o e,er4 user can i.e. manipulate that.
13.1. +'ring ,-.
0e use the aspect oriented prorammin modell in case of the transaction handlin. 7o (e define an aspect
for the transaction scope for the *A8s and the 7er,ices. 0here e,er4 *A8 method runs in a sinle
transaction. @or the 7er,ice methods (ho can ha,e more than one *A8 method calls (e set the transaction
scope in such a case that one sinle transaction is around of such a couple of *A8 method calls. 7o all data
modifications must be o# and than commit them. +f at least one modification is not o# than all are rolled bac#.
/his is done b4 definin a so called ad,iceE
<t2Jadvice id="serice&xAdice" transaction-manager="transaction"ana!er">
<t2Jattrib!tes>
<t2Jmethod name="D" &ro&agation="EEF%IEED" />
</t2Jattrib!tes>
</t2Jadvice>
<t2Jadvice id="dao&xAdice" transaction-manager="transaction"ana!er">
<t2Jattrib!tes>
<t2Jmethod name="D" &ro&agation="EEF%IEED" />
</t2Jattrib!tes>
</t2Jadvice>
@urther (e need to define the so called pointcutsE
<ao&Jconfig>
<ao&J&ointc!t id="!ui1erice"ethods"
e2&ression="execution8D de.forsthaus.!ui.serice.D.D8..::" />
<ao&J&ointc!t id="serice"ethods"
e2&ression="execution8D de.forsthaus.backend.serice.D.D8..::" />
<ao&J&ointc!t id="dao"ethods"
e2&ression="execution8D de.forsthaus.backend.dao.D.D8..::" />
<ao&Jadvisor advice-ref="!ui1erice&xAdice" &ointc!t-ref="!ui1erice"ethods" />
<ao&Jadvisor advice-ref="serice&xAdice" &ointc!t-ref="serice"ethods" />
<ao&Jadvisor advice-ref="dao&xAdice" &ointc!t-ref="dao"ethods" />
</ao&Jconfig>
0e a,e the pointcuts an expression that the execution should depend on the (ell named pac#ae
structure.
All the transactions no( are manaed b4 a sprin transaction manaer for that (e select the
;ibernate/ransaction2anaer.
<bean id=#transactionCanager#
class="or!.sprin!frame+ork.orm.hibernate-.;ibernate&ransaction"ana!er">
<&ro&erty name="session'actor?" ref="session'actor?" />
</bean>
/his is the round (h4 4ou couldn1t find an4 lines in the code that includes (ords li#e tx.commit or
tx.rollbac#. /he (hole transaction handlin is manaed b4 sprin1s transaction manaer.
13.2. +'ring/+e%urit)
@or authentication and authori"ation (e ta#e the sprin9securit4 frame(or# (hich is formerl4 named as Acei
frame(or#.
0e use the *A8 Authentication b4 codin an implementation of 7prin 7ecurit41s User*etail7er,ice. Dou1ll
find it in the class de.forsthaus.polic4.model.Polic42anaer
public class ,olicyCanager implements 9ser3etails>ervice$ >eriali"able 6
@urther (e coded an o(n User implementation in the class de.forsthaus.polic4.model.User+mpl that extends
from 7prin 7ecurit41s User class. public class 9ser0m&l extends 9ser implements >eriali"able$
de.forstha!s.&olicy.9ser 6
/his user is extended for a user to#en (ith it (e encr4pt and decr4pt an pass(ord addition. 3ead more of it
Zksample2 Help to prevent the global warming by writing cool software. http:www.forstha!s.de
Last modification: 05.10.2012 - 21 -
in the section of 1/he one9time9pass(ord implementation1 .
All the (irein of the beans and confiurations is done in the sprin7ecurit4Context.xml 4ou1ll found in the
folder "#ossFsrcFmainFressources.
13.3. +e%urit)/Con%e't
7oG (e are usin a borderla4out in the 1index."ul1 !the main pae& and put all other called "ul9paes in the
center area of itG (e ha,e an other (or#in as pae orientationed apps.
As a result (e al(a4s ha,e the same U36E WF"#ossFindex."ul .
/herefore (e cannot (or# (ith an url9based securit4 manaement li#e the most 1sprin9securit41
samples sho(s for this.
9 /he Administration menu point includes the (hole securit4 administrationG the users and 6oin lo list.
9 /he securit4 is build on top of the sprin9securit4 frame(or# and is extended for roups and roup9rihts.
9 +n the most simple examples the roles are defined for A*2+HN386=G U7=3N386= or AU=7/N386=.
/his is to small for us and is not customi"able (ithout ma#in code modifications and re9deplo4 the
application. :ecause (hat is a user PPP A user in a bier business firm can (or#s in a department of
boo#inG in,oicinG in,entor4G productionG salesG promotion X
And these cateories can ha,e sub cateories. +n fact (e do not (ant that the user 5ohn *oe ha,e full
access to all departments (ho he is not (or#in for. /herefore a sinle role 1386=NU7=31 is absolutl4 not
fine enouh to handle such a complex riht tree . 7o in practice (e need a finer ranulated access for such
users. 7econdl4 (e o a(a4 from the xml confiuration for the rihtsFroles.
0e confiure the securit4 access in database tables and do extend the securit4 for a roup and roup9riht.
@urther (e need not a ne( tomcat start to consider chanes in the scurit4 of paes or e,ents. 8nl4 a ne(
loin is needed that modifications of rihts can act.
At lastE A riht in the (orld of sprin9securit4 is onl4 a 7/3+HA.
0hile (e secure the application in the C8*= and manae these in tables 0= and 8U3 CU7/82=37
(ould ha,e the abbilit4 to customi"e the accessFriht.
0hile (e do not secure (ith a 386=97trin either (e secure (ith a 3+A;/97trin (e can assin a roup of
riht9strins to a loicall4 closed A38UP.
7o 3+A;/7G A38UP7 and A38UP93+A;/7 are defined b4 the de,eloper (ho #no(s (hat compoents are
in the application and are (or#in toether.
All other pieces li#e 386=7 and 386=9A38UP7 can be modifiedFextended b4 the customer if
neededFallo(ed.
User !ha,e&
Y99 3oles !ha,e&
Y99 3ole9Aroups !ha,e& extended for m4 needs
Y99 Aroup93ihts !ha,e& extended for m4 needs
Y99 3ihts
Users
9 All users ha,e the riht to edit her o(n peronal data li#e the nameG pass(ord.
9 User 3oles are assined in the administration area ZUser 3oles[.
9 Customi"able

User93oles
9;ere are the roles assined to the Users. +t1s possible to assin se,eral 3oles to a user.
9 Customi"able

3oles
9 Predefined 3oles.
9 Customi"able
3ole9Aroups
9 Predefined 3ole9Aroups.
9 Customi"able
Zksample2 Help to prevent the global warming by writing cool software. http:www.forstha!s.de
Last modification: 05.10.2012 - 22 -
Aroups
9 Predefined Aroups.
9 *eclared from the de,eloper (ho #no(s the component +*sG not customi"able.
Aroup93ihts
9 Predefined Aroup93ihts.
9 *eclared from the de,eloper (ho #no(s the component +ds and (hat components to be used for a loical
unit li#e 1customer.edit1 or 1customer.ne(1G not customi"able.
3ihts
9 Predefined 3ihts. =ach used component can ha,e a riht as a 7trin.
9 *eclared from the de,eloper (ho #no(s the component +*sG not customi"able.
0e can secure a component in code b4 three methodsE
1. settin it ,isibleFun,isible !in code&
2. settin it readonl4 !in code&
3. creation time (ith ifIJJ !in "ul&
0e can secure a method in code b4 (or#in (ith the V7ecured!& annotation.
@or settin the riht (e call in the users 0or#space the isAllo(ed!7trin riht& method.
/his methode do onl4 searchin the 7trin in the list of the users 1ranted3ihts1 and results a trueFfalse.
btn7a,e.setMisible!(or#space.isAllo(ed!\buttonN:ranch*ialoNbtn7a,e\&&]
8emem!erE /he (a4 (e do implementin the securit4 is the hihest possibilit4 of fine ranulation of rihts
for an application. /herefore the price is a hiher memor4 consumption for e,er4 loed in user. At time
e,er4 loed in user ha,e ha,e up to 1%- rihts !7trins& that are stored in memor4 at ser,er side. Dou must
decide (hat ranulation 4ou need for 4our application. +n most 1open1 (eb applications it1s enouh to ha,e
se,eral 3oles li#e AdminG User or Auest. 7o 4ou can chec# the riht aainst the users role.
13.4. +'ring 0ean s%o'es
About (hat scopes areG please read the sprin documentation. +n short supports sprin 5 t4pes of bean
scopesE
1. session < 3eturns a sinle bean instance per ;//P session.
2. lobal7ession < 3eturns a sinle bean instance per lobal ;//P session.
3. sinleton !default& < 3eturns a sinle bean instance per sprin +oC container.
%. protot4pe < 3eturns a ne( bean instance each time (hen re)uested.
5. re)uest < 3eturns a sinle bean instance per ;//P re)uest.
;ere (e (ill onl4 sho( (hich scopes are needed for a scalable multi9user approach.
=ackend>
8ur *A8s are all statelessG means the4 ha,e no properties but onl4 methods. +n that case (e can use the
scope 1sinleton1 (hich is the default scope. A session scope is not needed because b4 a properl4
confiured transaction manaement.
A ood explaination for that i found in a forumE
There is no need to make your DAOs session-scoped.
"ho!gh Hibernate session has a state# !nder properly config!red transaction management its state is
bo!nd to transactions $i.e. different %&' methods called inside the same transactions share the same
session# whereas the same method called from different transactions use different sessions(.
)o# yo!r %&'s are effectively stateless# and sho!ld be singleton*scoped $i.e. defa!lt scope(.
J
^ +f yo! enco!nter problemsiss!es with that you can always scale up. +n ,,- of the cases a singleton
Zksample2 Help to prevent the global warming by writing cool software. http:www.forstha!s.de
Last modification: 05.10.2012 - 23 -
s!ffices as long as it is stateless of co!rse J
0ith scale up he means ta#e a shorter lifec4cle of the scope.
?rontend>
@or the AU+ controllers (e set all the bean scopes to protot#peG because (e (ant all times a defined clean
ui controller and not callin controllers (ith old stuff.
13.5. ,n one/time/'ass$ord im'ementation.
@or a more safet4 access to a (eb application it can be secured (ith a d4namic pass(ord.
7uch is called as an one9time9pass(ord mechanism. +n our case of the Z#sample2 (here (e ha,e
an username and a pass(ord and (ouldn1t do chanin much of the codes for sho(in ho( it
(or#s so (e do it in that case that the enerated one9time9pass(ord is appended to the existin
pass(ord.
7uch a mechansim (or#s in the follo(in (a4E
/he one9time9pass(ord is the result from a to#en that is encr4pted in con>unction (ith a timestamp
and ha,e an exactl4 scope of ,alid time.
7o for decr4ptin bac# (e must ha,e the same time !(e ha,e a time (indo( of 2 minutes& on the
other side for ettin the correct result. Dou (ill find some firms that offers such to#eni"ers that
loo#s li#e a memor4 stic# that enerates the one9time9pas(ord. 8n the ser,erside a code does
decr4pt this one9time9pass(ord bac# if it corresponds (ith the user to#en. @or that there can be a
timer in the stic# that must be s4nchroni"ed (ith the time that the ser,er soft(are used.
@or demonstratin (e ha,e a little >a,a proram as the third
subpro>ect. +t1s been named as Ke4AenZ#oss. /he folder structure
loo#s li#e in the picture.
Dou can build them (ith the ma,en pluin for =clipse. Dou
can reach them in the context menu of the pro>ect li#e the
fiurE
A console output from the first ma,en9install 4ou see on the
left side.
T01(DU >canning for &ro8ects...
T01(DU ------------------------------------------------------------------------
T01(DU /!ilding IeyGen-'oss->0.0.4->1*,>%D
T01(DU
T01(DU 0dJ de.daib!ts!JIeyGen-'ossJ8arJ0.0.4->1*,>%D
T01(DU tas'-segmentJ TinstallU
T01(DU ------------------------------------------------------------------------
T01(DU Treso!rcesJreso!rcesU
T01(DU 9sing defa!lt encoding to co&y filtered reso!rces.
T01(DU Tcom&ilerJcom&ileU
T01(DU 1othing to com&ile - all classes are !& to date
T01(DU Treso!rcesJtest<eso!rcesU
T01(DU 9sing defa!lt encoding to co&y filtered reso!rces.
T01(DU Tcom&ilerJtest+om&ileU
T01(DU 1othing to com&ile - all classes are !& to date
T01(DU Ts!refireJtestU
!rl = htt&J//re&o4.maven.org/maven;
3ownloadingJ htt&J//re&o4.maven.org/maven;/org/a&ache/maven/s!refire/s!refire-
8!nit/;.V.;/s!refire-8!nit-;.V.;.&om
!rl = htt&J//re&o4.maven.org/maven;
Zksample2 Help to prevent the global warming by writing cool software. http:www.forstha!s.de
Last modification: 05.10.2012 - 2% -
3ownloadingJ htt&J//re&o4.maven.org/maven;/org/a&ache/maven/s!refire/s!refire-&roviders/;.V.;/s!refire-&roviders-;.V.;.&om
!rl = htt&J//re&o4.maven.org/maven;
3ownloadingJ htt&J//re&o4.maven.org/maven;/org/a&ache/maven/s!refire/s!refire-8!nit/;.V.;/s!refire-8!nit-;.V.;.8ar
T01(DU >!refire re&ort directoryJ 3JWmavenM&ro8ectsWmavenWIeyGen-'ossWtargetWs!refire-re&orts
-------------------------------------------------------
E > >
-------------------------------------------------------
here are no tests to r!n.
<es!lts J
ests r!nJ 0$ (ail!resJ 0$ ErrorsJ 0$ >'i&&edJ 0
T01(DU T8arJ8arU
T01(DU /!ilding 8arJ 3JWmavenM&ro8ectsWmavenWIeyGen-'ossWtargetWIeyGen-'oss-0.0.4->1*,>%D.8ar
T01(DU TinstallJinstallU
T01(DU 0nstalling 3JWmavenM&ro8ectsWmavenWIeyGen-'ossWtargetWIeyGen-'oss-0.0.4->1*,>%D.8ar to
+JW9sersWsgeW.m;Wre&ositoryWdeWdaib!ts!WIeyGen-'ossW0.0.4->1*,>%DWIeyGen-'oss-0.0.4->1*,>%D.8ar
T01(DU ------------------------------------------------------------------------
T01(DU /90=3 >9++E>>(9=
T01(DU ------------------------------------------------------------------------
T01(DU otal timeJ ? seconds
T01(DU (inished atJ (ri Pan 45 4:JV0J;: +E ;040
T01(DU (inal CemoryJ 4C/XC
T01(DU ------------------------------------------------------------------------
Dou can start the application (ith a riht clic# on the 2ain7tart.>a,a
class. K3un asLK5a,a ApplicationL
8n (indo(s s4stems the application is started in the tas#bar.
/he context menu sho(s the options 4ou ha,e. 17ettins...1 is for set the users
securit4 to#en. 1enerate pass(ord...1 enerates the pass(ord to#en.
+nput the same securit4 to#en that 4ou
ha,e set in the User *ialo for the
tested User.
/he encr4pted routine i,es bac# all times a 6 diits to#enG so (e must onl4 cut
these 6 diits at the end at the input pass(ord for e,aluatin if is o#.
+n the bac#round this proram ets the time for the encr4ptin routine from the same ser,er as
the Z#sample2 application. 7o be sure 4ou ha,e a runin internet connection. +f there1s no internet
connection found the routine uses the s4stem time from 4our machine.
+n this case 4ou can s4nchroni"e manuall4 b4 pressin the 6oin
*ialos button for ettin the time from the s4nchronisation ser,er. /his
time 4ou must no( set up on 4our local machine (here the
Ke4AenZ#oss application is runnin.
Zksample2 Help to prevent the global warming by writing cool software. http:www.forstha!s.de
Last modification: 05.10.2012 - 25 -
+f all setup is done. 7tore a to#en i.e. 1a:c%*1 in the user dialos securit4 to#en field for a user. /he
same to#en 4ou sa,e to the to#eni"er application !Ke4AenZ#oss&.
+f 4ou no( (ill loin onl4 (ith 4our username and #no(n pass(ord 4ou (ill fail. Dou must et a
one9time9pass(ord from the to#eni"er application. /hese pass(ord to#en 4ou must added at the
end of 4our normal pass(ord and it (ill be accepted.
/he enerated pass(ord9to#en ha,e a ,alid time of 2 minutes defined in the codes.
',. J"nit testing

+n the sub9pro>ect 1sprin9hibernate9bac#end1 (e ha,e append
>Unit tests for se,eral *A8s. /he tests are in the folder
srcFtestF>a,a and the confiuration files are in the folder
srcFtestFresources. /hese are common folders in a ma,en build
s4stem.
/he tests can be called b4 All/est.>a,a that calls all sinle
/est*A8s classes or b4 sinle runnin the /est*A8s.
/o run the tests (e need a little bit of (or# (ith some
confiurations because the tests are should runnin aainst a real database. +n
srcFtestFresources are the file applicationContext9h29db9test.xml (hich holds the beans and
the datasourceFtransaction manaer confiuration. +t1s all
copied and a little bit ne( arraend from se,eral #no(n confi
files that 4ou ha,e seen 4et in the pro>ects.
/he interestin part is the definin of the ;29database@iller. +t1s
the same declaratioon as in the "#oss main subpro>ect
!frontend&. +n the codes the class (ill start a ;2 database ser,er
and creates the table and data definition from a resource file
1create7ample.s)l1.
/he loadinFcallin of this confiuration is defined in the
ParentClass of our *A8 tests called 1:asis;ibernate/est.>a,a1 .
/he used *A8s in the tests are auto(ired b4 usin of
annotations. /hat1s all. ;a,e fun (ith it.
'%. ;ow To@s and special components
15.1. 1o$ to !uid a %ustom %onstraint $ith a 'arameter
+n the user dialo (e ha,e a text field for the used pass(ord and a re/4ped pass(ord field for
chec#in that the pass(ord is (ritten correctl4. @or hat case that (e do compare the t(o
pass(ords (e (rite a small constraint b4 implementin the +onstraint interface.
0e do that b4 callin our constraint (ith the component to be compared as a parameter.
/he ,alidate methode that (e must o,erride refers to the component that et this constraint class. 7o (e can
easil4 compare the o,erhanded component from the constructor call (ith the ,alidated component and his
,alue. Dou can find this class in the pac#ae de.forsthaus.(ebui.util .
Zksample2 Help to prevent the global warming by writing cool software. http:www.forstha!s.de
Last modification: 05.10.2012 - 26 -
&!blic class 1oEm&ty*ndEN!al>trings+onstraint im&lements +onstraint$ 8ava.io.>eriali"able 6
private static final long serialGersion%ID = V05;4Y3??53:4:::0Y4=B
private final +om&onent com&are+om&onentB
public 1oEm&ty*ndEN!al>trings+onstraint@+om&onent com&are+om&onentA 6
super@AB
this.com&are+om&onent = com&are+om&onentB
7
ZDverride
public void validate@+om&onent com&$ Db8ect val!eA throws .rong)al!eE2ce&tion 6
if @com& instanceof e2tbo2A 6
final >tring entered)al!e = @>tringA val!eB
if @com&are+om&onent instanceof e2tbo2A 6
if @entered)al!e.isEm&ty@AA 6
throw new .rong)al!eE2ce&tion@com&$
=abels.!et0abel@#message.error.+annot/eEm&ty#AAB
7
final >tring com&ared)al!e = @@e2tbo2A com&are+om&onentA.get)al!e@AB
if @!entered)al!e.eN!als@com&ared)al!eAA 6
throw new .rong)al!eE2ce&tion@com&$
=abels.!et0abel@#message.error.<ety&ed,asswordC!st/e>ame#AAB
7
7
7
7
4ou can setup this custom constraint in >a,a (ith .setConstraint!& li#e the next linesE
/FF
F >ets the )alidation by setting the accordingly constraints to the fields.
F/
private void do>et)alidation@A 6
. . .
!sr,assword.set+onstraint@#1D EC,O#AB
!sr,assword<ety&e.set+onstraint@new 1oEm&ty*ndEN!al>trings+onstraint@this.!sr,asswordAAB
. . .
7
15.2. 1o$ to de%are a %ustom %onstraint $ith 'arameter in zum
/he normal (a4 to setup an in:uild constraint in "uml (e declare such an thin li#e thisE
<te2tbo2 id="txtb2%ser2>ass+ord"
ty&e="pass+ord"
val!e="H5controller.user.pass+ord6"
constraint="no empt?" /I
+f (e (ould setup our custom constraint (ith a parameter in "uml (e must do that in an >a,a li#e
(a4 that (e first ma#e an instance of our custom constraint and than use it in the constraint taE
<te2tbo2 id="txtb2%ser2>ass+ord"
ty&e="pass+ord"
val!e="H5controller.user.pass+ord6"
constraint="no empt?" /I

</row>
<"scri&t>
1oEm&ty*ndEN!al>trings+onstraint cc = new NoEmptyAndEqualStringsConstraint txtb!"ser!#assword $
</"scri&t>
. . .
<!-- ,assword <e-y&e / ,asswort .iederhol!ng -->
<row>
. . .
<te2tbo2 id=#t2tbM9serM,assword<ety&e#
ty&e=#&assword#
constraint%&$'cc(& />

</row>
Zksample2 Help to prevent the global warming by writing cool software. http:www.forstha!s.de
Last modification: 05.10.2012 - 2' -
15.3. ")'eCon2erters
0e use /4peCon,erters in the case if (e need a special format of a beans propert4 ,alue for
renderin in a databinded 6istbox. As a sample (e ha,e a loo# on the "uml code pieces for a
6istboxE
<listbo2 id="list3ox3ookin!EealAccounts"
model="H5controller.bookin!s6"
selected0tem="H5controller.selected3ookin!6" vfle2="true"
style="border(top(+idth* $pxJ border(left(+idth* $pxJ border(ri!ht(+idth* $pxJ border(bottom(+idth* #pxJ"
toolti&te2t="45c*l89listbox.tooltiptext9:6" width="#$$7"
height="#$$7" m!lti&le="false">
<listhead si"able="true">
<listheader id="listheader2#"
sclass="'D0ist3ox;eader#" image="/ima!es/icons/builder.!if"
label="id" sort="auto" width="#$7" />
. . .
</listhead>
<listitem id="list3ox3ookin!EealAccounts0istItem"
self="H5eachK9bookin!96" val!e="H5bookin!6"
forward="onDoubleClickKonEdit3ookin!">
<listcell label="H5bookin!.id6"
style="text(ali!n* ri!ht" />
<listcell label="H5bookin!.documentDateC
converterK9de.forsthaus.+ebui.util.bindin!.conerter.DateConerter96" />
. . .
/he /4peCon,erter class code loo#s li#e this E
/FF
F 3atabinding+onverter 3irectionJ D!t&!t only
F
F >o!rceJ 3ate$ imestam& <br>
F 3estinationJ =abel$ =istcell<br>
F
F 3ateformat is retrieved from the 03=abelsM2.&ro&erties or if not declared
F than as
F
F E2am&lesJ <listcell label=
F #Z6&erson.birthdate$ converter=Hde.forst....converters.3ate+onverterH7# /><br>
F <label val!e=
F #Z6&erson.birthdate$ converter=Hde.forst....converters.3ate+onverterH7# /><br>
F
F @author bbr!hns
F @author >te&han Gerth
F
F/
public class 3ate+onverter implements y&e+onverter 6
public 3ate+onverter@A 6
7
/F
F @non-PavadocA
F
F Zsee
F org."'oss."'&l!s.databind.y&e+onverterRcoerceo/ean@8ava.lang.Db8ect$
F org."'oss."'.!i.+om&onentA
F/
public Db8ect coerceo/ean@Db8ect arg0$ +om&onent arg4A 6
// this is an output converter$ no action here
return nullB
7
/F
F @non-PavadocA
F
F Zsee org."'oss."'&l!s.databind.y&e+onverterRcoerceo9i@8ava.lang.Db8ect$
F org."'oss."'.!i.+om&onentA
F/
public Db8ect coerceo9i@Db8ect arg0$ +om&onent arg4A 6
if @arg0 == nullA 6
return nullB
7
return get3ateime@@3ateA arg0AB
7
/FF
F (ormat the date/time. <br>
F
Zksample2 Help to prevent the global warming by writing cool software. http:www.forstha!s.de
Last modification: 05.10.2012 - 2- -
F @return >tring of date/time
F/
protected >tring get3ateime@3ate dateA 6
if @date != nullA 6
return (33ate(ormat.!etDate'ormater@A.format@dateAB
7
return ##B
7
7
15.4. 1o$ to o2erhand 'arameters to %om'osers
A common as#ed )uestion is ho( to o,erhand a parameter to a composer. 8ften this results from
the follo(ed application desin.
+f a user doubleclic# on a 6istitem in a 6istbox he (ill open a dialo (indo( (here he can modif4
the data of the selected item.
@or this purpose (e can create the modal (indo( b4 o,erhandin the selected 6istitem or bean in
the follo(ed (a4.
@or this oal (e for(ard the mouse e,ent of a doubleClic# from the 6istbox to a defined method in
the controllerFcomposer. /he first sample is a databinded listbox (here the second sample is
(or#in (ith an item3endererE
1. databinded
<listbo2 id="list3ox%ser"
model="H5controller.users6" selected0tem="H5controller.selected%ser6" m!lti&le="false">
<listhead si"able="true">
<listheader id="lh2%ser0o!in=ame" label="0o!in=ame" width="#$$7" />
</listhead>
<listitem self="H5eachK9user96" val!e="H5user6"
forward="onDoubleClick=onDoubleClickedItem">
<listcell label="H5user.lo!inname6" />
</listitem>
2. item3enderer
public class Cy0tem<enderer implements =istitem<enderer$ >eriali"able 6
ZDverride
public void render@=istitem item$ Db8ect dataA throws E2ce&tion 6
final 9ser !ser = @9serA dataB
=istcell lcB
lc = new =istcell@user)get*oginname@AAB
lc.set,arent@itemAB
item.set)al!e@dataAB
+om&onents+trl.appl?'or+ard@item$ #onDoubleClick=onDoubleClickedItem#AB
7
A common failure from beinners is to declare such an 1o(n1 named e,ent in a not "# conform (a4
li#e doubleClic#ed=,ent!=,ent e,ent&G m4=,ent!=,ent e,ent& or do7omethin!=,ent e,ent&.
+n this case an error (ill occur li#e 1/his is not an "# e,ent...1. /he "# namin con,ention re)uire
that an "# _,ent beins (ith 1on1 li#e 1onCreate1G 1onClic#1G 1onChane1 (here 1on1 is (ritten in
lo(erCase letters.
+n both implementation (a4s (e code the on*oubleClic#ed+tem method li#e these samplesE
++ ,) -atabinded version)
public void onDoubleClickedItem@Event eventA 6
// he Hselected9serH is filled by the binder
9ser an9ser = get>elected9ser@AB
if @an9ser != nullA 6
// create the modal window with the !ser as &aram.
show3etail)iew@an9serAB
7
7
Zksample2 Help to prevent the global warming by writing cool software. http:www.forstha!s.de
Last modification: 05.10.2012 - 2. -
++ .) /tem0enderer version
public void onDoubleClickedItem@Event eventA 6
// get the selected ob8ect from the listbo2
// and +*> it to the right ty&e
=istitem item = list/o29ser.get>elected0tem@AB
if @item != nullA 6
// +*> *13 >D<E %E >E=E+E3 D/PE+
9ser an9ser = @9serA item.get)al!e@AB
// create the modal window with the !ser as &aram.
show3etail)iew@an9serAB
7
`
/FF
F D&ens the detail view. <br>
F Dverhanded some &arams in a ma& if needed. <br>
F
F @param an9ser
F @throws E2ce&tion
F/
private void show3etail)iew@>ec9ser an9serA throws E2ce&tion 6
/F
F .e can call o!r 3ialog "!l-file with &arameters. >o we can call them
F with a ob8ect of the selected item. (or handed over these &arameter
F only a Ca& is acce&ted. >o we &!t the ob8ect in a %ashCa&.
F/
%ashCa&<>tring$ Db8ect> ma& = new %ashCa&<>tring$ Db8ect>@AB
ma&.&!t@#!ser#$ an9serAB
// call the "!l-file with the &arameters &ac'ed in a ma&
try 6
E2ec!tions.createComponents@#/.E/-01(/&ages/!ser/!ser3ialog."!l#$ null$ ma&AB
7 catch @final E2ce&tion eA 6
lo!!er.error@#onD&en.indowJJ error o&ening window / # L e.getCessage@AAB
`
`
Ho( (e ta#e a loo# at the modal (indo( and ho( (e read bac# the o,erhanded param.
0e suppose that (e extend our controllerFcomposer from "# Aeneric@or(ardComposer that do the
(irein and for(ardin stuff for us.
. . .
pri,ate User user] FF settersFetters
. . .
ZDverride
public void do*fter+om&ose@+om&onent windowA throws E2ce&tion 6
super.do*fter+om&ose@windowAB
/FF
F >et an HaliasH for this com&oser name in the "!l file for access.<br>
F >et the &arameter Hrec!rseH to HfalseH to avoid &roblems with
F managing more than one "!l-file in one &age. Dtherwise it wo!ld be
F overridden and can ends in c!rio!s error messages.
F/
self.set*ttrib!te@#controller#$ this$ falseAB
`
/FF
F <ead bac' the overhanded !ser from the &aram<br>
F/
if @arg.containsIey@#!ser#AA 6
set9ser@@9serA arg.get@#!ser#AAB
`
`
public void on+reate5modal9ser.indow@Event eventA throws E2ce&tion 6
binder = @*nnotate3ata/inderA event.getarget@A.get*ttrib!te@#binder#$ trueAB
binder.load*ll@AB
modal9ser.indow.doCodal@AB
7
Zksample2 Help to prevent the global warming by writing cool software. http:www.forstha!s.de
Last modification: 05.10.2012 - 3$ -
T4(E if 4ou need access from 4our modal dialo (indo( bac# to the parent composer that called
this modal (indo( than do o,erhand the complete controller self instead onl4 one or a fe( params.
+n that case 4ou ha,e full control to all of its ,arsG components and methods.
// overhanded this controller self in the &aramCa&
final Ca&<>tring$ Db8ect> ma& = +ollections.sin!leton"ap@[main+ontroller\$ thisAB
// call the "!l-file
E2ec!tions.createComponents@"!l(ile,ath1ame$ &arent$ ma&AB
And the code in the called composer loo#s li#e thisE
&rivate 9serCain+ontroller !serCain+ontrollerB // setters/getters
&rivate 9ser=ist+ontroller !ser=ist+ontrollerB // setters/getters
&rivate 9ser !serB // setters/getters
ZDverride
public void do*fter+om&ose@+om&onent windowA throws E2ce&tion 6
super.do*fter+om&ose@windowAB
. . .
/FF
F 4. Get/>et the ,arent/Cain+ontroller and set this controller bac'.<br>
F ;. +hec' if their is a selected bean in the ,arent/Cainmod!le. 0f yes
F than get them.
F/
if @arg.containsIey@#main+ontroller#AA 6
set9serCain+trl@@9serCain+trlA arg.get@#main+ontroller#AAB
// >E %0> +D1<D==E< D %E mod!leHs ,arent/Cain+ontroller
get9serCain+trl@A.set9ser3etail+trl@thisAB
// GE/>E the selected bean.
if @get9serCain+trl@A.get>elected9ser@A != nullA 6
set>elected9ser@get9serCain+trl@A.get>elected9ser@AAB
7
7 else 6
set>elected9ser@nullAB
7
. . .
`
An other (a4 to o,erhand parameters are the (a4 to do it in the 7ession 8b>ect.
FF .etCurrent!& i,es bac# the session for the current thread
org."'oss."'.!i.>essions.!etCurrent@A.set*ttrib!te@#&aram4#$ #his is a test.#AB
FF read bac# the param from the session ob>ect.
Db8ect ob8 = >essions.!etCurrent@A.get*ttrib!te@#test#AB
>ystem.out.&rintln@ob8AB
Dou can do the same (ith the nati,e ;ttp session. +.e. if 4ou need to o,erhand such a param to the
bac#end (here no "# libs are resides. 0e ta#e therefore help b4 the sprin frame(or#.
FF set the param in the nati,e 7ession
8ava2.servlet.htt&.%tt&>ession session = @%tt&>essionA org."'oss."'.!i.>essions.!etCurrent@A.get1ative>ession@AB
session.set*ttrib!te@#test;#$ #his is a second test with native %tt& session#AB
FF read bac# the param from the nati,e 7ession
org.s&ringframewor'.web.conte2t.reN!est.<eN!est*ttrib!tes atr =
org.s&ringframewor'.web.conte2t.reN!est.<eN!est+onte2t%older.currentEe@uestAttributes@AB
8ava2.servlet.htt&.%tt&>ession session = @%tt&>essionA atr.get>essionC!te2@AB
>ystem.out.&rintln@session.get*ttrib!te@#test;#AAB
15.5. 3ong running o'erations 4 "he 5%ho 52ent
6on runnin operations are not ood thins in (eb applications. +t lac#s about the http protocol
!re)uestFresponse& to inform the user (hat is oin on and ho( is the proress of such an process.
Z# ha,e se,eral methods to help to inform the user (hen such a process starts and ends. 0e
implemented the echo event to inform the user (ith a messae alon the duration of the process
of insertin demo customer records in a loop.
/he messae appears if (e start the process and the messae closes if the process is read4. As
Zksample2 Help to prevent the global warming by writing cool software. http:www.forstha!s.de
Last modification: 05.10.2012 - 31 -
lon as the process ta#es the users cannot do an4thin else in this (indo( means that the bus4
messae is li#e modal.
0e can see in the codes that (e ha,e et the translated messae from the i39labelsNCC.properties
file.
/hese codes are in the de.forsthaus.'e!ui.Init(pplicationCtrl.)a$a class.
/FF
F Event=istener for the inserted 4000 c!stomers /!tton.<br>
F he creation of the records r!ns in an Echo-event that shows the !ser a
F b!sy message.
F/
public final class Dn+lic'4000Eventlistener implements Event=istener 6
ZDverride
public void onEvent@Event eventA throws E2ce&tion 6
// we create the records in an Echo-event to show a message to the
// !ser for this long r!nning o&eration.
+lients.sho+3us?@=abels.!et0abel@#message.0nformation.=ongD&eration0s<!nning#A$ trueAB
Events.echoEent@#on+reate4000+!stomers#$ start.indow$ nullAB
7
7
/FF
F +alls the long r!nning method that creates the records and closes
F the echo event message if ready.
F
F @param event
F @throws E2ce&tion
F/
public void on+reate4000+!stomers@Event eventA throws E2ce&tion 6
create3emo+!stomers@4000AB// the long r!nning &rocess
+lients.sho+3us?@##$ falseAB // close the message
7
15.6. #oda (+ear%h) (iaogs that are getting !a%k an o!6e%t
+maine 4ou ha,e a form (ith se,eral data fields and one or more of it (ill et their data b4 selectin it from a
list. 7uch a list is often called as a *rop*o(n6ist. 0ith the "# frame(or# 4ou can sol,e this b4 usin a listbox
(ith moldIaselecta and ro(sIa1b. /he outstandin feature of such a component is that the cstarterc is in most
cases a little button direct at the end of the input field and e,e4bod4 #no(s that he must clic# on this button
to drop do(n the list. +f 4ou need some more options for limitin the count of records (hen the list appears
4ou need an other (a4 to sol,e this issue.
8ne possibilit4 is to ta#e a so called bandbox component and place all needed data limitin functionalit4 (ith
the listbox on it.
/he second (a4 (e (ill sho(n in this article is to build a search:ox class (ith a modal (indo(. @or ha,in
the same beha,iour (e place a little starter button riht next the input field that (e (hish to fill (ith a
selected item from our 7earch6ist:ox. /he ad,antae of our solution is that (e can easil4 extended the
7earch6ist:ox for needed limitation components and loic features and get !ack an o!ject of the needed
bean from a (indo( in a modal state.
@or this re)uirement (e let our 7earch6ist:ox classes created b4 a pri,ate constructor that (e called in a
static (a4. 7o (e ha,e an simple call for those boxes li#eE
Bean bean = XXXXXSearchListBox.show(parentComponent);
<imple<earch.ist=o+.java>
Zksample2 Help to prevent the global warming by writing cool software. http:www.forstha!s.de
Last modification: 05.10.2012 - 32 -
public class /ranch>im&le>earch=ist/o2 extends .indow implements >eriali"able 6
private static final long serialGersion%ID = 4=B
private static final =ogger lo!!er = =ogger.!et0o!!er@/ranch>im&le>earch=ist/o2.classAB
private =istbo2 listbo2B
// the windows title
private >tring Mtitle = =abels.!et0abel@#message.0nformation.>im&le>earch#A L # / # L
=abels.!et0abel@#common./ranch#AB
// 4. =istheader
private >tring Mlist%eader4 = =abels.!et0abel@#common.3escri&tion#AB
// the windows height
private int Mheight = V00B
// the windows width
private int Mwidth = 300B
// the ret!rned bean ob8ect
private /ranche branche = nullB
// he service from which we get the data
private /ranche>ervice branche>erviceB
/FF
F he +all method.
F
F @param &arent
F he &arent com&onent
F @return a /eanDb8ect from the list/o2 or n!ll.
F/
public static /ranche show@+om&onent &arentA 6
return new /ranch>im&le>earch=ist/o2@&arentA.get/ranche@AB
7
/FF
F ,rivate +onstr!ctor. >o it can only be created with the static show@A
F method.<br>
F
F @param &arent
F/
private /ranch>im&le>earch=ist/o2@+om&onent &arentA 6
super@AB
set,arent@&arentAB
create/o2@AB
7
Advanced<earch.ist=o+.java
As (e ha,e seen in the abo,e part of the modal search dialos stor4 (e build all searchFselection
components in a modal (indo( component and b4 closin these (indo( (e can et bac# the selected
ob>ect from the list.
Doucll disco,er that these search*ialo is not reall4 recommended for handlin hue data amounts. +n fact
the underl4in "# 6ist2odel6ist (ill handle the data pain on the ser,er and send bac# to the clients listbox
onl4 such count of records that are defined in the pae7i"e but holds all of the loaded records on the ser,er.
7o the memor4 usae can increase rapidl4.
As a 0ebui frame(or# the in,ol,ed "# component cannot and need not #no( (hat bac#end technolo4 (e
use. 7o (e can catch the onPain!& e,ent from the pain component to manipulate the outoin database
call for the needed records. +n this case (e et a real database pain (here onl4 the needed records for
presentin in the listbox are loaded from the db.
7o (e call in our onPain=,ent6istener a refreshCodel@startA method that calls a bac#end method (ith
parameters for pae7i"e and start:43ecord that i,es bac# a 3esult8b>ect that holds the result6ist and the
totalCount of the potentiall4 possible records (ithout pain.
/FF
F #on,aging# Event=istener for the &aging com&onent. <br>
F <br>
F +alc!lates the ne2t &age by c!rrent,age and &age>i"e val!es. <br>
F +alls the method for refreshing the data with the new row>tart and
F &age>i"e. <br>
F/
public final class Dn,agingEvent=istener implements Event=istener 6
ZDverride
public void onEvent@Event eventA throws E2ce&tion 6
Zksample2 Help to prevent the global warming by writing cool software. http:www.forstha!s.de
Last modification: 05.10.2012 - 33 -
,agingEvent &e = @,agingEventA eventB
int &age1o = &e.get*ctive,age@AB
int start = &age1o F get,age>i"e@AB
if @lo!!er.is3eb!gEnabled@AA 6
lo!!er.deb!g@#--> J # L start L #/# L get,age>i"e@AAB
7
// refresh the list
refreshCodel@startAB
7
7
/FF
F <efreshes the list by calling the 3*D methode with the modified search
F ob8ect. <br>
F
F @param so
F >earchDb8ect$ holds the entity and &ro&erties to search. <br>
F @param start
F <ow to start. <br>
F/
Z>!&&ress.arnings@#!nchec'ed#A
void refreshCodel@int startA 6
// clear old data
get=istCodel=ist@A.clear@AB
// init the model
<es!ltDb8ect ro = get/ranche>ervice@A.get*ll/ranches@start$ get,age>i"e@AAB
=ist</ranche> res!lt=ist = @=ist</ranche>A ro.get=ist@AB
M&aging.setotal>i"e@ro.getotal+o!nt@AAB
// set the model
set=istCodel=ist@new =istCodel=ist@res!lt=istAAB
listbo2.setCodel@get=istCodel=ist@AAB
7
0+tended<earch.ist=o+.java
As (e see in the part 1 and part 2 of the modal search dialos stor4 (e build all searchFselection
components in a modal (indo( component and b4 closin these (indo( (e can et bac# the selected
ob>ect from the list.
*atabase Pain is necessar4 if the application should be fast. 8,er all (e need a functionalit4 (ith (hich
(e can limit the amount of possible list results b4 manipulatin the ,alue of a table field for the s)l (here
clause. @or our =xtended7earch6ist:ox (e do this b4 addin a textbox component and a search button. /he
textbox recei,es sins that must be occur (ith the data of the table field. 0e search in our bac#end method
(ith the dli#ec #e4(ordG so that e,er4 record comes bac# (here in their field d*escriptionc i.e. the sins dard
exists. 0e start the retrie,in of the records b4 pressin the search button riht next the textbox. +f (e (ant
et all records that (e must clear the textbox and press the search button aain.
@rom the bac#end (e et bac# a helper class calledE 3esult8b>ect!& . /his class holds onl4 t(o thins. @irst a
eneric list that (e must cast them bac# and second an int ,alue that represents the total7i"e of possible
records !not the paed onecs si"e&.
public class <es!ltDb8ect implements >eriali"able 6
private static final long serialGersion%ID = 4=B
// holds a generic =ist
private =ist<K> listB
// holds an int
private int total+o!ntB
public <es!ltDb8ect@A 6
7
public <es!ltDb8ect@=ist<K> list$ int total+o!ntA 6
super@AB
set=ist@listAB
setotal+o!nt@total+o!ntAB
7
public =ist<K> get=ist@A 6
return listB
7
public void set=ist@=ist<K> listA 6
this.list = listB
Zksample2 Help to prevent the global warming by writing cool software. http:www.forstha!s.de
Last modification: 05.10.2012 - 3% -
7
public int getotal+o!nt@A 6
return total+o!ntB
7
public void setotal+o!nt@int total+o!ntA 6
this.total+o!nt = total+o!ntB
7
7
Dou (ill find all three search:oxes (or#in in the customer dialo.
15.7. 52ent7ueues. We are !uiding a +tatus0ar %ontroer.
0ith "#5 comes the =,ent?ueues. +maine that these ne( features are (or#in li#e lobal
listeners. 7oG (hat is nearer than buildin a 7tatus:arController (ith this ne( techni)ue.
/he code for the 7tatus:arController sho(s that (e must declare onl4 a (indo( component in the
"ul file. /he status:ar areas are created per >a,a in the controller. 7o (e ha,e in this sample three
columns that (e (an1t fill from time to time if needed.
/he first column is for sho(in informations of the current selected :ean in a module that (or#s
(ith the annotated databindin mechanism. /he second column sho(s the application ,ersion and
the third column should sho( the current used table schema. At a later time (e (ant to sho( ho(
to ma#e a hibernate dri,en application (or#in as a multi9tenanc4 application (here tenants can
ha,e their o(n table9schema.
+n the doAfterCompose method (e declare the lobal 6isteners. 0here in the on=,ent (e no(
read bac# the e,ent1s data and cast it to a 7trin for sho(in the messae in the correspondin
column.
// =istener for selected <ecord
Event]!e!es.lookup@#selectedDb8ectEvent]!e!e#$ Event]!e!es.DE1A&O>$ trueA.s!bscribe@new Event=istener@A 6
ZDverride
public void onEvent@Event eventA throws E2ce&tion 6
final >tring msg = @>tringA event.get3ata@AB
>tat!s/ar+trl.this.stat!s/ar>electedDb8ect.set=abel@>tat!s/ar+trl.this.Mlabel>electedDb8ect L msgAB
77AB
/he (hole class is nothin more than these linesE
/FF
F =======================================================================<br>
F >tat!s/ar+ontroller. <br>
F =======================================================================<br>
F .or's with the Event]!e!es mechanism of "'. *=l needed com&onents are created
F in this class. 0n the "!l-tem&late declare only this controller with Ha&&lyH
F to a win>tat!s/ar window com&onent.<br>
F
F 3eclaration in the "!l-fileJ<br>
Zksample2 Help to prevent the global warming by writing cool software. http:www.forstha!s.de
Last modification: 05.10.2012 - 35 -
F
F <&re>
F < borderlayo!t >
F . . .
F < !-- >*9> /*< *<E* -- >
F < so!th id=#so!th# border=#none# margins=#4$0$0$0#
F height=#;0&2# s&littable=#false# fle2=#tr!e# >
F < div id=#div>o!th# >
F
F < !-- he >tat!s/ar. +om&s are created in the +ontroller -- >
F < window id=#win>tat!s/ar# a&&ly=#56stat!s/ar+trl7#
F border=#none# width=#400Q# height=#400Q# />
F
F < /div >
F < /so!th >
F < /borderlayo!t >
F </&re>
F
F call in 8ava to act!ali"e a col!mns labelJ
F
F <&re>
F Event]!e!es.loo'!&@^N!otB!ser1ameEvent]!e!e^N!otB$ Event]!e!es.3E>ID,$ tr!eA.&!blish@
F new Event@^N!otBon+hange>electedDb8ect^N!otB$ n!ll$ ^N!otBnew )al!e^N!otBAAB
F </&re>
F
F >&ring bean declarationJ
F
F <&re>
F < !-- >tat!s/ar+ontroller -->
F < bean id=#stat!s/ar+trl# class=#de.forstha!s.web!i.!til.>tat!s/ar+trl#
F sco&e=#&rototy&e#>
F < /bean>
F </&re>
F
F sinceJ "' 5.0.0
F
F @author sgerth
F
F/
public class >tat!s/ar+trl extends Generic(orward+om&oser implements >eriali"able 6
private static final long serialGersion%ID = 4=B
private final static =ogger lo!!er = =ogger.!et0o!!er@>tat!s/ar+trl.classAB
/F
F LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
F *ll the com&onents that are defined here and have a corres&onding
F com&onent with the same HidH in the "!l-file are getting a!towired by o!r
F He2tends G(+/ase+trlH Generic(orward+om&oser.
F LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
F/
protected .indow win>tat!s/arB // a!towired
// 9sed +ol!mns
private +ol!mn stat!s/ar>electedDb8ectB
private +ol!mn stat!s/ar*&&)ersionB
private +ol!mn stat!s/arable>chemaB
// =ocali"ed labels for the col!mns
private final >tring Mlabel>electedDb8ect = =abels.!et0abel@#common.>elected>ign#A L # #B
private final >tring Mlabel*&&)ersion = ##B
private final >tring Mlabelable>chema = =abels.!et0abel@#common.able>chema#A L #J #B
/FF
F 3efa!lt constr!ctor.
F/
public >tat!s/ar+trl@A 6
super@AB
7
ZDverride
public void do*fter+om&ose@+om&onent windowA throws E2ce&tion 6
super.do*fter+om&ose@windowAB
// =istener for selected <ecord
Event]!e!es.lookup@#selectedDb8ectEvent]!e!e#$ Event]!e!es.DE1A&O>$ trueA.s!bscribe@new Event=istener@A 6
ZDverride
public void onEvent@Event eventA throws E2ce&tion 6
final >tring msg = @>tringA event.get3ata@AB
>tat!s/ar+trl.this.stat!s/ar>electedDb8ect.set=abel@>tat!s/ar+trl.this.Mlabel>electedDb8ect
L msgAB
7
7AB
// =istener for a&&lication)ersion
Event]!e!es.lookup@#a&&)ersionEvent]!e!e#$ Event]!e!es.DE1A&O>$ trueA.s!bscribe@new Event=istener@A 6
ZDverride
public void onEvent@Event eventA throws E2ce&tion 6
final >tring msg = @>tringA event.get3ata@AB
>tat!s/ar+trl.this.stat!s/ar*&&)ersion.set=abel@>tat!s/ar+trl.this.Mlabel*&&)ersion L msgAB
7
7AB
Zksample2 Help to prevent the global warming by writing cool software. http:www.forstha!s.de
Last modification: 05.10.2012 - 36 -
// =istener for able>chema1ame
Event]!e!es.lookup@#table>chemaEvent]!e!e#$ Event]!e!es.DE1A&O>$ trueA.s!bscribe@new Event=istener@A 6
ZDverride
public void onEvent@Event eventA throws E2ce&tion 6
final >tring msg = @>tringA event.get3ata@AB
>tat!s/ar+trl.this.stat!s/arable>chema.set=abel@>tat!s/ar+trl.this.Mlabelable>chema L msgAB
7
7AB
7
/FF
F *!tomatically called method from "'.
F
F @param event
F/
public void on+reate5win>tat!s/ar@Event eventA 6
final Grid grid = new Grid@AB
grid.set%eight@#400Q#AB
grid.set.idth@#400Q#AB
grid.set,arent@this.win>tat!s/arAB
final +ol!mns col!mns = new +ol!mns@AB
col!mns.set>i"able@falseAB
col!mns.set,arent@gridAB
this.stat!s/ar>electedDb8ect = new +ol!mn@AB
this.stat!s/ar>electedDb8ect.set=abel@this.Mlabel>electedDb8ectAB
this.stat!s/ar>electedDb8ect.set.idth@#50Q#AB
this.stat!s/ar>electedDb8ect.set>tyle@#bac'gro!nd-colorJ R3Y3+3EB colorJ bl!eB#AB
this.stat!s/ar>electedDb8ect.set,arent@col!mnsAB
this.stat!s/ar*&&)ersion = new +ol!mn@AB
this.stat!s/ar*&&)ersion.set=abel@this.Mlabel*&&)ersionAB
this.stat!s/ar*&&)ersion.set.idth@#35Q#AB
this.stat!s/ar*&&)ersion.set>tyle@#bac'gro!nd-colorJ R3Y3+3EB colorJ R((0000B#AB
this.stat!s/ar*&&)ersion.set,arent@col!mnsAB
this.stat!s/arable>chema = new +ol!mn@AB
this.stat!s/arable>chema.set=abel@this.Mlabelable>chemaAB
this.stat!s/arable>chema.set.idth@#45Q#AB
this.stat!s/arable>chema.set>tyle@#bac'gro!nd-colorJ R3Y3+3EB colorJ bl!eB#AB
this.stat!s/arable>chema.set,arent@col!mnsAB
7
7
0e can no( call such an =,ent?ueue from e,er4(here in the application. @or example in the
article list controller (e find such a line in the method (here (e select a list+tem from the list:oxE
// show the ob8ects data in the stat!s/ar
final >tring str = =abels.!et0abel@#common.*rticle#A L #J # L an*rticle.get*rtI!r"be"eichn!ng@AB
Event]!e!es.lookup@#selectedDb8ectEvent]!e!e#$ Event]!e!es.DE1A&O>$ trueA.&!blish@
new Event@#on+hange>electedDb8ect#$ null$ strAAB
0e limited the scope for this method to 1*=7K/8P1. :e sure that the caller and the sender ha,e
the same scope. +f 4ou pla4 a little bit (ith it 4ou (ill find the scope 1APP6+CA/+8H1.
0o0 that1s reat. *o 4ou feel the po(er of itP
DesG (e can build eas4 a chat s4stem (ith itG or can send 2essaes to e,er4(here (ho has run
the same application. 0e (ill tr4 this in the next thread.
15.8. 52ent7ueues. We are !uiding a #essage0ar %ontroer.
0ith the same mechanism (e can no( build our o(n messain s4stem for sendin messaes to
all loed in users. 0e (ill build this s4stem as eas4 as (e can so (e let them declared onl4 as a
(indo( component in the "ul file.
. . .
<!-- >*9> /*< *<E* -->
<so!th id="south" border="none" height="22px" s&littable="false">
<div id="di1outh" align="left"
style="float* leftJ paddin!* $px" width="#$$7">
Zksample2 Help to prevent the global warming by writing cool software. http:www.forstha!s.de
Last modification: 05.10.2012 - 3' -
<borderlayo!t width="#$$7" height="22px">
<west border="none" width=",$px">
<!-- he Cessage/ar. +om&s are created in the +ontroller -->
<window id="+in"essa!e3ar" a&&ly="45messa!e3arCtrl6"
border="none" width=",$px" height="22px" />
</west>
<center border="none">
<!-- he >tat!s/ar. +om&s are created in the +ontroller -->
<window id="+in1tatus3ar" a&&ly="45status3arCtrl6"
border="none" width="#$$7" height="22px" />
</center>
</borderlayo!t>
</div>
</so!th>
. . .
/he read4 implemented component are loo#s li#e this picture (ith onl4 t(o icons in it. /he red mail
icon is for sho(in the messae. /his icon is blin#in if there comes ne( messaes in and the
messae reader is not opened. /he riht next icon is for openin a little (indo( for (ritin a
messae text (ho can be send to all users.
/he messae s4stem ha,e t(o classes. /he first class is the messae:arCtrl.>a,a (hich holds the
lobal listener for the messae and the the t(o icons (ith their e,ent6isteners. 0e create all
components in this class so (e ha,e onl4 to declare the controllers (indo( component in the "ul
file.
+n the afterCompose!& method (e can enable that if a messae come in that a (indo( pops up
and sho(s this messae or onl4 the incomin mail icon is blin#in. @urther (e et the user name
from our 7prin7ecurit4 Context;older.
ZDverride
public void do*fter+om&ose@+om&onent windowA throws E2ce&tion 6
super.do*fter+om&ose@windowAB
try 6
!ser1ame = @@9ser0m&lA
>ec!rity+onte2t%older.!etContext@A.get*!thentication@A.get,rinci&al@AA.get9sername@AB
7 catch @E2ce&tion eA 6
e.&rint>tac'race@AB
7
// =istener for incoming messages @ sco&e=*,,=0+*0D1 A
Event]!e!es.lookup@#testEvent]!e!e#$ Event]!e!es.A>>0ICA&IO=$ trueA.s!bscribe@new Event=istener@A
6
ZDverride
public void onEvent@Event eventA throws E2ce&tion 6
final >tring msg = @>tringA event.get3ata@AB
// +hec' if em&ty$ than do not show incoming message
if @>tring9tils.isEmpt?@msgAA 6
returnB
7
setCsg@msgAB
if @msg.indow == nullA 6
/FF
F 0f yo! whish to &o&!& the incoming message than !ncomment
F these lines.
F/
// getCsg.indow@AB
// @@e2tbo2A
// getCsg.indow@A.get(ellow@#tb#AA.set)al!e@getCsg@AAB
Cessage/ar+trl.this.btnD&enCsg.set0mage@
#/images/icons/incomingMmessage4M4Y24Y.gif#AB
7 else 6
@@e2tbo2A getCsg.indow@A.get(ellow@#tb#AA.set)al!e@getCsg@AAB
7
7
7AB
Zksample2 Help to prevent the global warming by writing cool software. http:www.forstha!s.de
Last modification: 05.10.2012 - 3- -
7
@or sendin a messae (e create our so called 0n&!tCessagee2t/o2 . +t1s a little modal
(indo( that ha,e a textbox and a button in it. :4 clic#in the 1send1 button the (ritten text is et
bac# to the callers method and the (indo( is closed.
+f the incomin messae text (indo( is al(a4s open G the incomin mail icon (ill not blin#.
15.9. (ash!oard modues
0e ha,e chaned the ,isual main entr4 content se,eral times. 7o (e o a little bit modern and at
time after a successful loin the center content is filled (ith the *ashboard and se,eral modules in
it.
@or the module holder la4out (e (or# (ith a combination from hbox and t(o cells. 7o (e need not
a portalla4out or Column6a4out (hich is not in the ce ,ersion of "#.
All modules ha,e their o(n loic and if needed their o(n data access and returns as div@s.
0e can arrane the modules in the dashboard main controller as simple as...
public class 3ashboardCain+trl extends G(+/ase+trl implements >eriali"able 6
. . .
/FF
F *!tomatically called method from "'.
F
F @param event
F @throws E2ce&tion
F/
public void on+reate5window3ashboard@Event eventA throws E2ce&tion 6
/FF
F +E1E< area
F/
div3ashboard+enter.a&&end+hild@3ashboard*&&lication1ews=ist+trl.sho+@;50$ true$ Y00000AAB
div3ashboard+enter.a&&end+hild@3ashboardable<ecords+o!nter+trl.sho+@;00$ true$ Y00000AAB
/FF
F E*> area
F/
div3ashboardEast.a&&end+hild@3ashboard+alendar+trl.sho+@4VYAAB
// div3ashboardEast.a&&end+hild@3ashboardGoogleranslate+trl.show@Y5AAB
div3ashboardEast.a&&end+hild@3ashboardOo!t!be)ideo+trl.sho+@4X:AAB
div3ashboardEast.a&&end+hild@3ashboard//+1ews+trl.sho+@V:0$ #no#AAB
7
. . .
/here are historical old stuff in the dashboard."ul from "#sample2 so here is a plain dashboard."ul sho(ed
from the open/ruulse pro>ect.
<K2ml version="#.$" encoding="%&'()"K>
<Ktaglib !ri=#htt&J//www."'oss.org/ds&/web/core# &refi2=#c#K>
<Kvariable-resolver class=#org."'oss."'&l!s.s&ring.3elegating)ariable<esolver#K>
<"' 2mlns="http*//+++.zkoss.or!/2$$,/zul"
2mlnsJh="http*//+++.+-.or!/#.../xhtml"
2mlnsJ2si="http*//+++.+-.or!/2$$#//"01chema(instance"
2mlnsJw="http*//+++.zkoss.or!/2$$,/zk/client"
Zksample2 Help to prevent the global warming by writing cool software. http:www.forstha!s.de
Last modification: 05.10.2012 - 3. -
2siJschema=ocation="http*//+++.zkoss.or!/2$$,/zul http*//+++.zkoss.or!/2$$,/zul/zul.xsd">
<window id="+indo+Dashboard" apply%"${dashboardCtrl}" border="none"
width="#$$7" hfle2="#">
<hbo2 align="stretch" &ac'="stretch" sclass="Dashboard"
width="#$$7">
<!-- CD39=E +D1E1 *<E* -->
<cell>
<vbo2 align="stretch" &ac'="stretch" width="#$$7">
<div id="diDashboardCenter">
<!-- %ere comes the +E1E< mod!les -->
<!-- div.elcome+enter.a&&end+hild@3ashboard1ews+trl.show@AAB -->
</div>
</vbo2>
</cell>
<!-- E*> *<E* -->
<cell width="2<$px">
<vbo2 align="stretch" &ac'="stretch" width="2<$px">
<div id="diDashboardEast">
<!-- %ere comes the E*> mod!les -->
<!-- div3ashboardEast.a&&end+hild@3ashboard3ateting+trl.show@AAB -->
</div>
</vbo2>
</cell>
</hbo2>
</window>
</"'>
Hothin more todo. E9& /hat1s a ,er4 simple la4out and (or#ed in all bro(sers b4 automaticall4 fit to the
bro(ser si"e.
/here are a fe( modules in Z#sample2 that should sho( ho( eas4 all this can fit toether. :ecause (e (rap
the modules content in a roupbox or a panel (e can attach a toolbar in the header (hich holds the title and
some icons or buttons. :ehind the buttons (e access the modules loic li#e openin the list for selectin a
son in the Dou/ube module.
Zksample2 Help to prevent the global warming by writing cool software. http:www.forstha!s.de
Last modification: 05.10.2012 - %$ -
An other module t4pe li#e the bbc ne( module sho(s an iframe (ith a lin# to the ,endors >a,a7cript (idet.
Capsulate all needed loic in the module self and create the "# comps in >a,a codeO 7o 4ou need onl4 to put
the controller in the place 4ou (ant !my3iv.a&&end+hild@3ashboard3ateting+trl.show@AAB &. 2ost of our modules ha,e a
timer in it for refreshin the content. /here are no limitations. +t1s at 4our hands to do some nice dashboard
modules. Attached a picture from an earl4 stae desin for a protot4pe dashboard module for open/ruuls
that should sho( the cluster status.
'*. Avoid common fail"res
16.1. (ata0inder faiures
^Pae is alread4 co,ered b4 another *ata :inder. Cannot be co,ered b4 this *ata :inder aainJ.
Dou (ill et this error if 4ou ha,e more than one "ul9files usin *ata:inder+nit (hich is per default
co,ered the (hole pae. 7o 4ou onl4 need to define that each of this databinders are co,ered onl4
the "ul9file (here it1s in. Dou can done this b4 specify the root component $e.g. a .window/ or a
.div/( in the Z0 %ata1inder+nit attrib!te.
<Kinit class=#org."'oss."'&l!s.databind.*nnotate3ata/inder0nit# root=#root#K>
or
<Kinit class=#org."'oss."'&l!s.databind.*nnotate3ata/inder0nit# arg0=#./window+!stomer3etail# K>
<window id=\window+!stomer3etails . . .
Zksample2 Help to prevent the global warming by writing cool software. http:www.forstha!s.de
Last modification: 05.10.2012 - %1 -
'5. ;ow to replace the inAemor# ;2 sample data!ase.
8ut of the box runs Z#sample2 (ith an in2emor4 ;2 database for immediatel4 data access. /his
is (or#in in the follo(in (a4E
:4 startup the application in a ser,let container li#e /omcat there is a bean confiured that starts
an in2emor4 ;2 db ser,er and fills the database (ith tablesG se)uences and demo data from a
script file.
All confiuration files are in the srcFmainFresouces folder of the pro>ects. +n the frontend pro>ect
!called "#oss& is a file called %ustomize/a''i%ationConte:t.:m. +n it (e confiure the
datasource for the application. +n fact this is one of t(o files (hich (e replace (ith our postres
database confiuration (hen (e let build and run the application on our (eb ser,er.
@or chanin the database from ;2 to 4our postre7?6G m47?6 or other ;ibernate supported
databases comment out the section (ith the ;2 database filler. +f 4ou are interested ho( this (or#s
ha,e a loo# in the correspondin class de.forsthaus.h2."?2;221ampleData'iller.
<!-- ====================================================== -->
<!-- %0> ,=*+E 0> (D< +D1(0G9<01G *1 P3/+ +D11E+0D1 -->
<!-- *13 +D1(0G9<E 0 01 (0=EJ 8dbc.&ro&erties -->
<!-- ====================================================== -->
<!-- -->
<bean id="data1ource"
class="or!.sprin!frame+ork.Ldbc.datasource.Drier"ana!erData1ource">
<&ro&erty name="drierClass=ame" val!e="45Ldbc.drierClass=ame6" />
<&ro&erty name="url" val!e="45Ldbc.url6" />
<&ro&erty name="username" val!e="45Ldbc.username6" />
<&ro&erty name="pass+ord" val!e="45Ldbc.pass+ord6" />
</bean>
<!--
comment o!t this bean if yo! donHt !se the the defa!lt internally
-->
<!-- %; database with the a!tomatic filled demo data by start!& -->
<bean class="de.forsthaus.h2."?2;221ampleData'iller">
<&ro&erty name="data1ource" ref="data1ource">
</&ro&erty>
</bean>
<!tilJ&ro&erties id="hibernate>roperties">
<&ro& 'ey="hibernate.dialect">56hibernate.dialect7</&ro&>
<&ro& 'ey="hibernate.sho+2s@l">56hibernate.showMsNl7</&ro&>
<&ro& 'ey="hibernate.format2s@l">56hibernate.formatMsNl7</&ro&>
</!tilJ&ro&erties>
/he second file to ad>ust is the >dbc.properties file (hich holds the parameters for the database li#e
dri,er classnameG userG pass(ord. Dou must chane it to the needs of the used database.
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
R /y !sing the defa!lt demo %; database. R
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
8dbc.driver+lass1ame=org.h;.3river
8dbc.!rl=8dbcJh;Jmem/"'sam&ledbBCD3E=%>]=3/
8dbc.!sername=sa
8dbc.&assword=
hibernate.dialect=org.hibernate.dialect.%;3ialect
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
R /y !sing the ,D>G<E> db with the insert scri&t from folder R
R "'oss/db/+reateestables.ith3ataM,ostgres.sNl R
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
R 8dbc.driver+lass1ame=org.&ostgresNl.3river
R 8dbc.!rl=8dbcJ&ostgresNlJ//localhostJ5V3;/testMdb
R 8dbc.!sername=toledo
R 8dbc.&assword=yo!r,assword
R hibernate.dialect=org.hibernate.dialect.,ostgres
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
R /y !sing the my>]= 5.4 db with the insert scri&t from folder R
R "'oss/db/+reateestables.ith3ataMCy>]=M5M4.sNl R
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
R 8dbc.driver+lass1ame=com.mysNl.8dbc.3river
R 8dbc.!rl=8dbcJmysNlJ//localhostJ330Y/testMdb
R 8dbc.!sername=root
R 8dbc.&assword=&assword
R hibernate.dialect=org.hibernate.dialect.Cy>]=3ialect
Zksample2 Help to prevent the global warming by writing cool software. http:www.forstha!s.de
Last modification: 05.10.2012 - %2 -
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
R %ibernate ]!ery 3eb!g o!t&!t in the console R
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
hibernate.showMsNl=false
hibernate.formatMsNl=tr!e
:e sure 4ou ha,e the needed >dbc dri,er for the additional database declared in the ma,en
pom.xml from the frontend pro>ect !"#oss&. :4 usin the Postre7?6 database it loo#s li#e the
declaration in the next lines. 2odif4 the ,ersion to 4ou needs.
<!-- ,ostgre>]= database -->
<de&endency>
<gro!&0d>&ostgresNl</gro!&0d>
<artifact0d>&ostgresNl</artifact0d>
<version>X.0-:04.8dbcV </version>
</de&endency>
6ast but not least (e must install the preferred database ser,er and let run the scripts for creatin
the tables and demo data. +n the frontend pro>ect folder called ;d! are se,eral script files for such
thins.
0e ha,e t(o script files for other databases li#e the ;2. /he files Create"est(0<.ostgres.s=
Create"est"a!esWith(ata<.ostgres.s= is for our preferred postre7?6 database (here the
Create"est"a!esWith(ata<#)+73<5<1.s= spends us And4C for the m47?6 database.
'6. The package str"ct"re
18.1. 0a%kend
de.forsthaus.bac#end.dao ;olds all *A8 +nterfaces.
de.forsthaus.bac#end.dao+mpl ;olds all *A8 method implementations.
de.forsthaus.bac#end.ser,ice ;olds all 7er,ice +nterfaces.
de.forsthaus.bac#end.ser,ice+mpl ;olds all 7er,ice method implementations.
de.forsthaus.bac#end.model ;olds all domain model classes.
de.forsthaus.bac#end.util ;olds all utils and helper classes.
de.forsthaus.bac#end.bean ;olds all read4 bean classes i.e li#e special ;?6 list.
2appins for )ueries (ith areat fields.
srcFmainFresourcesFS ;olds all confiuration9filesG mappin9files.
srcFtestF>a,a ;olds all 5unit tests
srcFtestFresources ;olds all confiuration files for the 5unit tests.
18.2. >rontend
de.forsthaus
de.forsthaus.common.menu.S ;olds the classes for buildin a treemenu or a menu:ar from one
menumetadata modell out of a xml9file.
de.forsthaus.example ;olds the class for insertin randoml4 customer dataG and the
/estController for the test."ul.
de.forsthaus.ui.ser,ice +nterfaces for the loin ser,ice.
de.forsthaus.ui.ser,ice.impl ;olds all 7er,ice method implementations.
de.fortshaus.h2 ;olds the ;2 *: filler. /hat creates the /ables and create the demo data
from a s)l9file.
de.forsthaus.polic4 ;olds the classes for loin the lo9in process and the pass(ord encoder.
de.forsthaus.polic4.model ;olds the class that implements the sprin9securit4 User*etail7er,ice .
Zksample2 Help to prevent the global warming by writing cool software. http:www.forstha!s.de
Last modification: 05.10.2012 - %3 -
and some classes in (or# for user countin.
de.forsthaus.ser,ices.report.ser,ice ;olds the 3eportser,ice +nterface.
de.forsthaus.ser,ices.report.ser,ice.impl ;olds all 7er,ice method implementations.
de.forsthaus.statistic ;olds the statistic class from "#. /he ,alues are sho(n in the pre pae
at application start.
de.forsthaus.util 7ome helper classes. /he Z#ossComponent/reeUtil.>a,a is a nice util
that sho(s 4ou a complete "# component tree in the console.
de.forsthaus.(ebui ;olds initiali"in classes.
de.forsthaus.(ebui.modulname* ;olds the controllers for the module1.
de.forsthaus.(ebui.modulname*.model ;olds the +tem3enderers and helper classes for the module1.
de.forsthaus.(ebui.modulname*.report ;olds the reports for module1 if exists.
de.forsthaus.(ebui.modulname+ ;olds the controllers for the module2.
de.forsthaus.(ebui.modulname+.model ;olds the +tem3enderers and helper classes for the module2.
de.forsthaus.(ebui.modulname+.report ;olds the reports for module2 if exists
de.forsthaus.(ebui.index ;olds the controller for the index pae.
de.forsthaus.(ebui.ser,ice ;olds the 7er,ice +nterfaces for the ser,cies li#e report or loin.
de.forsthaus.(ebui.ser,ice+mpl ;olds the 7er,ice method implementations.
de9forsthaus.(ebui.securit4.modulname+ ;olds the securit49controllers for the module2.
de.forsthaus.(ebui.securit4.modulname+.model ;olds the +tem3enderers and helper classes for the module2.
de.forsthaus.(ebui.util ;olds the utils and helper classes and o(n components.
de.forsthaus.(ebui.util.bindin.con,erter Con,erters for the listitems in databinded listboxes.
de.forsthaus.(ebui.util.pain /he re,ised ;elper class for ettin a paed record list that can be
sorted on the *:.
de.forsthaus.(ebui.util.searchdialos /he three search6ist:oxes s#eletonsE 7imple7earch6ist:ox]
Ad,anced7earch6ist:ox] =xtended7earch6ist:ox]
de.forsthaus.(ebui.util.searchin 7ome helper classes for the 7earch class for the ;ibernate9Aeneric9*A8
frame(or#.
srcFmainFresources ;olds all confiuration9files.
Fdb ;olds the scripts for creatin the database F tables Fse)uences and demo
data for a Postre7?6 or a 247?6 database.
18.3. 1istor) of %hanges
1'.Apr.2$12 &dded 2!nit tests for the backend %&'s. "hese tests are r!nning against the same sample data
!sed in the main application. "he !sed H2 database was created and filled with data at every test
start!p. "his sho!ld be r!nning o!t of the bo3
$6.Apr.2$12 43tend the doc!mentation a little bit abo!t a chapter 5dashboard mod!les5.
3$.2ar.2$12 &dding a paging mechanism to %ashboard6od!le &pplication 7ews.
1'.2ar.2$12 6odifications in the table scripts for let r!n Zksample2 against a my)8L %atabase. 6any thanks to
&ndy9.
$-.@eb.2$12 &dded a few new :o!"!be 6!sic ;ideo links. Have a look on the <%onots * )top the clocks< clip :*(
Love that song. =hat a se3y !nderwear>
$3.@eb.2$12 &dded an image slideshow to the entry page.
$1.@eb.2$12 ?pdated to @k 5.0.10.
$%.5an.2$12 "oday we have become a free 2Aebel licence for Zksample2 from the g!ys behind Zero"!rnarao!nd.
6any thanks for that.
Zksample2 Help to prevent the global warming by writing cool software. http:www.forstha!s.de
Last modification: 05.10.2012 - %% -
1%.*ec.2$1 &dded a few new :o!"!be m!sic video links.
1..Ho,.2$1 1!g fi3ed in order mod!l. Hope we can rewrite c!stomerorders mod!les new before Bhristmas.
1'.8ct.2$11 ?pdated to @k version 5.0.,.CL.2011101D.
26.7ep.2$11 1eca!se the often changed 11B 7ews ?AL. =e have add a new %ashboard mod!le for 5"he =all
)treet 2o!rnal5.
23.7ep.2$11 &dded a lot of new :o!"!be m!sic vid links.
25.Au.2$11 Ci3ed a few b!gs in old code for orders and c!stomers. "hanks to "homas for the hint. +f i had time
i will rewrite the c!stomer and orders mod!les.
11. Au. 2$11 Ci3ed a b!g in the B!stomer6od!le1ranch6od!le while not checking if special demo data are
deleted. "hanks to Aeiner.
25. 5un. 2$11 Lot of design changes for look more eE!al in chrome and +4.
1-. 5un. 2$11 3efactorin of the C3U* button9controller. Cleaned up from old stuff and added na,iation buttons. 7ee them
(or#in in the 1branch1G 1article1 and 1office1 modules.
'. 5un. 2$11 Added a ne( *ashboard module for startin the oole translator. /han#s to 11e##io11 for helpin (ith the correct
script components.1
3$. 2a4. 2$11 Added a buttonFmethod for closin all open tabs except the homeFdashboard tab.
26. 2a4. 2$11 Update the "# frame(or# to 5.$.'.1
1-. 2a4. 2$11 Added the missin 11m47ettins11 module for chanin the allo(ed data of the loed in user. /he ,alidation of the re9
t4ped pass(ord (or#s (ith an internal created bean for holdin the ret4ped strin and is ,alidated at ser,erside.
6. 2a4. 2$11 2odifications in the C3U* :utton Controller. Ho( it accepts 11Hull11 for special :uttons. UseCase is handlin an 8H=
record base entr4 for special app or firm parameters that needs onl4 the 11editG sa,eG cancel11 buttons.
2-. Apr. 2$11 Added a 5a,a7cript function for let the 2essae0indo(!Chat (indo(& from the 2essae:ar scroll automaticall4 to
the last entr4 for e,er4 ne( incomin messae. /han#s to daar(al-2.
httpEFF(((."#oss.orFforumFlistCommentF16$11
2$. Apr. 2$11 Added much more music !,ids&. Ai,e 11:ullmeister11 a chane. He9Do11s oriinal son 11:eautiful 2onster11 is not
a,ailable in m4 countr4. 7o there are re9mixes. 7eems (e must implement a search for interprets or titles. @eedbac#
in the Auestboo# please E9&.
1'. Apr. 2$11 Added a ne( *ashboard2odule for the applications histor4 of chanes. /herefore added ne( modelFdaoFser,ice
stuff.
1%. Apr. 2$11 +nspired b4 the :usinessPortal6a4out (e spend a ne( *ashboard2odule for ::CHe(s.
-. Apr. 2$11 &dded the co!nter for the Hibernate)tatistic table records and new yo!"!be m!sics. )o the Hibernate
Ferformance )tats r!ns !s away# we ma3imi@ed the possible c!stomers too !p to 250.000
2.. 2ar. 2$11 7ome code refactorins about the locali"ed *ataAccess=xceptions and correctin the scopes in the bac#end. 0ritin
a ne( Chapter for the used bean scopes in the Z#sample2 documentation.
2%. 2ar. 2$11 =xtended the *A8+mpl classes for the V3epositor4 Annotation in con>unction (ith a ne( entr4 in the application9
context9db.xml confiuration file. /hese let sprin con,ert the ,endor dependent ;ibernate =xceptions in common
dataAccess=xceptions.
1.. 2ar. 2$11 3emo,in the spreadsheet. 0e (ill (aitin until it1s offered for a ma,en build s4stem.
22. @eb. 2$11 2odifications in the C3U* :uttonController.
3. @eb. 2$11 Updated "# ,ersion to 5.$.6.@62$11$2$2
2-. 5an. 2$11 7eparate @ields for interpret F son title in the 4ou/ube *ashboard module.
2'. 5an. 2$11 Updated the ;ibernate9Aeneric9*A8 lib to ,ersion $.5.1 .
15. 5an. 2$11 @irst basic +mplementation of the "# spreadsheet 2.$ .
Zksample2 Help to prevent the global warming by writing cool software. http:www.forstha!s.de
Last modification: 05.10.2012 - %5 -
15. 5an. 2$11 Updated "# ,ersion to 5.$.6.@62$11$112
'. 5an. 2$11 /han#s to And4C for ma#in the chanes in the script9files for m47?6 5.1.
6. 5an. 2$11 :ufixes in the annotated databindin modules for a false 7etter.
5. 5an. 2$11 3efactorin of the bac#end. Addin missin comments !enlishFerman&. *eletin the old stuff for eneratin the
Primar4Ke4 for different databases independent from hibernate. Ho( it (or#s (ith hibernate controlled se)uences or
auto+ncremented fields.
%. 5an. 2$11 =xtend the menu talib used in the mainmenu.xml for the ta 1open1. Ho( (e can openFclose a menu+tem at creation
time. Creatin an 1about1 screen
2$. *e". 2$1$ Added the second *ashboard module for sho(in the data in,entor4.
/his module ha,e an build in timer for self refreshin (hich can be acti,ated at creation time.
7etup a ne( "ul s#eleton for the dashboard. /han#s 2adrua and 7imonPa4 for 1pac#Fstretch1 help.
16. *e". 2$1$ Added the missin methode for randoml4 selectin a son b4 the first creation of the *ashboard.
15. *e". 2$1$ Added the first *ash:oard 2odule. /he (elcome."ul is renamed to dashboard."ul.
/his *ash:oard module is for selectin a 4ou/ube ,ideo from a db list. ;a,e fun.
-. Ho,. 2$1$ @or u4s (ho (ould build this app from sourceG (e ha,e added a (or#around for the 5asper3eport failure b4 the
ma,en9build process for this pro>ect.
7ee FsrcFtestFresourcesFreadme.txt. 7eems this failure comes from the ma,en3 con,ersion of 5asper3eports. ;ope
the u4s repair the corrupt file expressl4.
5. Ho,. 2$1$ Added a Dou/ube ,ideo i@rame (here (e (ould stream (ee#el4 our most lo,ed music.
2. Ho,. 2$1$ +nformin the usersG that loadin the documentation in an i@rame is in proress. /han#s to /ome#.
httpEFF(((."#oss.orFforumFlistCommentF13'3-.
2$. 8#t. 2$1$ 7ource@ore ha,e chaned the documentation address.
25. 7ep. 2$1$ Addin a ne( menu entr4 for openin our blo.
1'. 7ep. 2$1$ Addin the bac#end classes for the calendar. Calendar is no( *atabase dri,en.
15. 7ep. 2$1$ Preparin the calendar for createFeditFupdate e,ents and implemented a *ate@ormatter for this.
12. 7ep. 2$1$ Updated libs to "# calendar 2.1 !@reshl4 12.$..2$1$& because a init problem.
'. 7ep. 2$1$ Updated to "# ,ersion 5.$.%.
1. 7ep. 2$1$ Added a modified script file for runin "#sample2 (ith a m47?6 5.1 database. /han#s to 1And4x1 .
3ead about needed modifications in pro>ect "#oss WFdbFm47?6.readme.
2'. Au. 2$1$ +mplemented a first simple messain s4stem. Dou can send s4stem (ide messaes. +ncomin messaes are
,isuali"ed (ith a blin#in icon in the left bottom corner.
25. Au. 2$1$ Updated the doc for the 7tatus:arController and bein (ith *4namic5asper. 7ome code refactorins.
23. Au. 2$1$ :ein implementation of the ZK Calendar component.
1-. Au. 2$1$ Added a ne( report for printin an 8rder (ith it1s positions. 7ho(s ho( to add a rand/otal sum.
11. Au. 2$1$ Added ne( reports for printinE User96ist F 7ecurit4E 3ihts96ist] Aroup96ist] 3oles96ist. 7ome of these report uses
the *4namic3eport:uilder from *4namic5asper (ich allo(s more control o,er the report. Additionall4 (e sho(s in it
ho( to use a Custom=xpression.
1$. 5ul. 2$1$ Added t(o more reports ! 8ffice6ist and :ranches6ist &G e,er4 report needs onl4 1$ min. for adoptin from an existin
one. A lot of desin chanes in the Administrator sections for the next comin databindin restructurin.
.. 5ul. 2$1$ @irst 5asper3eport build (ith the reat *4namic5asper frame(or#. 8nl4 pure 5a,aG no C26. 3eport is placed in the
Article module. 2ore ad,anced reports are comin in the next da4s.
6. 5ul. 2$1$ Chec#in of the ne( Z#sample2 based on "# 5.$.3 in Ftrun#. 2ore chanes comes in the next da4s.
%. 5ul. 2$1$ :ein to modif4in some modules to (or# completel4 (ith Annotated *atabindin mechanism. *ecreasin absolut
the 6oC. /hese annotated databinded modules ha,e an !adb& after the menu text.
All modules (ho ha,e more than one /A: became a main2oduleController for holdin the shared models and beans
for all related tabControllers.
3ead the docu for best Practice on sharin the models and not the binder. 0or#in (ith an additional css fileG
declared in the (eb.xml.
Zksample2 Help to prevent the global warming by writing cool software. http:www.forstha!s.de
Last modification: 05.10.2012 - %6 -
2. 5ul. 2$1$ Added a ne( 7tatus:arController (ith the ne( =,ent?ueues in "#5 that (or#s li#e a lobal listener.
Added a ne( User:arController (ith the ne( =,ent?ueues in "#5 that (or#s li#e a lobal listener.
1. 5ul. 2$1$ Updated the "# frame(or# ,ersion to 5.$.3.
3$. 5un. 2$1$ IIIIIII 6ast Z#sample2 ,ersion (ho1s based on "# 3.6.3 IIIIIII
3$. 5un. 2$1$ Added /08 more 7earch6ist*ialo s#eletons. Ho( (e ha,eE
1.& 7imple7earch6ist:oxE ZK pain on 7er,er7ide.
2.& Ad,anced7earch6ist:oxE *: Pain on *atabase]
3.& =xtended7earch6ist:oxE *: Pain f one data limitin feature.
All three 7earch*ialos are implemented in the Customer*ialo module for selectin a branch.
2.. 5un. 2$1$ Added a ne( modal 7earch6istbox*ialo that i,es bac# an 8:5=C/. Called 7imple7earch:ox. 0e implemented it
in the Customer Adress2odule for selectin a branch !:ranch7imple7earch:ox.>a,a&.
3. 5un. 2$1$ 3eplacement of the old ser,erPush mechanism (or#in (ith a 0or#er/hread ne( to (or# (ith a timer. :ecause this
application is sprin manaed. 7o our *atabase transactions are sprin manaed too. At time (e are not able to start
the 0or#er/hread in such a session context for callin *: methods. @urther it1s limit to 5 calls and self stoppedG as
lon as (e loed all *: calls !;ibernate 7tatistic&.
21. 2ai. 2$1$ @ixin bu in the flo( loic of the echo e,ents and an additional modal messae.
2$. 2ai. 2$1$ Added =C;8 =M=H/s. /he lon runnin process of insertin sample customer records no( runnin in an echo e,ent
and sho(s a locali"ed bus4 messae durin the process.
*8CU2=H/A/+8H updated.
1-. 2ai. 2$1$ Added a Paed=inding6ist0rapper ! painFsortinFsearchin on *:9side & for the listbox component that can (or#
(ith "#1s *ata:indin mechanism. 7o the :ranch module (or#s no( complete databinded. /he same for the rid (ill
follo( next times.
%. 2ai. 2$1$ Z#sample2 ,2.1 is a,ailable on source@ore.net as read4 to use (ar9file.
2. 2ai. 2$1$ Added a first Arid in Arid Mie( for the ;ibernate 7tatistic *: transactionsG (hich is implemented b4 a 7prin Aspect.
/he ,ie( (ill follo(in in the next da4s. /he ;ibernate7tatistics measures the time that a *: call needs and sho(s
all dependend model beans.
2$. Apr. 2$1$ +mpro,ed speed for the entr4 pae b4 done the countin of all table recordCounts in one transaction.
2$. 2ar. 2$1$ Chaned the desin for the menu and module content area. ;ope it1s nice.
.. 2ar. 2$1$ Added on all listpaes a refresh button !next help button & for resi"in the listbox and recalculate their paesi"e for
ad>ustin if the bro(ser si"e is chaned.
2. 2ar. 2$1$ 7e,eral desin chanes. :ufixes.
6. @eb. 2$1$ Updated to the 7prin3 frame(or#.
%. @eb. 2$1$ +mplementation of the missin Cancel :utton in all dialos.
2.. 5an. 2$1$ Chaned the st4le of the address tab in customers dialo. Chaned to comboboxes (ith icons.
1'. 5an. 2$1$ /oda4 (e chec#ed in this Z#sample2 application on 7ource@ore.net. 7ee thread under
httpEFF"#oss.orFforumFlistCommentF1$.-6
12. 5an. 2$1$ 0e (or# hardl4 on the last paes of the documentation. /he countdo(n for chec#in is runnin.
%. 5an. 2$1$ 0e fix the 1too man4 open files1 on ser,er. :ad bo4s attac# itO 3e9usin the (ebser,ice for ettin the eo9data.
2'. *e". 2$$. Chaned the complete update mechanism for the ip eo dataG because problems on the linux ser,er (ith 1too man4
open files1G (hen callin the 6ocator 0eb 7er,ice in a loop.
Ho( (e imported the eo data from a c,s into a table and can use it from there earl4 b4 the loin process.
22. *e". 2$$. @inished the basic 6oin 7tatistic. ;ard (or#OOO :>Brn (rites a mapper that maps the ;?6 areate fields to domain
bean properties. 2an4 than#s.
1.. *e". 2$$. 7plitted the 6oin6o module to 3 "ul1s f 3 controllers. Added some statistics.
15. *e". 2$$. Clearin code from old 3.5.x stuff. do8nCreateCommon!& not used an4more.
13. *e". 2$$. /ree 2enu entries are no( openend in /abs.
-. *e". 2$$. 3eplaced the last diits from the Users +P (ith 1xxx1 in the ui loin6o list because pri,ac4.
'. *e". 2$$. 2o,ed in all dialo (indo(s the C3U* buttons as imae:uttons to the toolbar.
Zksample2 Help to prevent the global warming by writing cool software. http:www.forstha!s.de
Last modification: 05.10.2012 - %' -
3. *e". 2$$. 3efactorin all *omainF*A8F7er,ice Classes to enlish names.
22. Ho,. 2$$. 7econd +p2Countr4 locator from a (eb7er,ice implemented.
2$. Ho,. 2$$. +p2Countr4 locator ne( in the 6oin lo.
1%. Ho,. 2$$. 3efactorin to a sprin9manaed frontend. 7prin97ecurit4 can no( (or# (ith the
Annotation V7ecured!& for securin methods.
Added a simulation of a one9time pass(ord to#eni"er. !/han#s to :>Brn for codes O&
Added 6ist@ooters in 83*=37 module. Clearin some code. :ufixes.
13. Ho,. 2$$. Z#7ample2 is no( the ne( pro>ect name.
23. 8#t. 2$$. IIIIIILL 6A7/ chec#in of the pro>ect code in 7ub,ersion on code.oole as 1"#NsampleNui "# IIIIIIIL
23. 8#t. 2$$. updatin to ZK ,ersion 3.6.3 @6 2$$.91$923
21. 8#t. 2$$. updatin to ZK ,ersion 3.6.3 @6 2$$.91$916
12. 8#t. 2$$. allo( chanin bet(een tree2enu and Pull*o(n2enu !/han#s to :>Brn for codes O&. 7ome 2odifications.
2.. 7ep. 2$$. Added a timer in the main borderla4out south area for dateFtime.
1'. 7ep. 2$$. Added se,eral ne( chart t4ps and icons.
1$. 7ep. 2$$. Added a pie chart to the customer dialo. 7ee tab 1Chart1. *ata created for custoHo 12$1 and 1211 \
25. Au. 2$$. Update to ZKoss ,ersion 3.6.3. @692$$.9$-92$
%. Au. 2$$. Update to ZKoss ,ersion 3.6.3. !compiled from source&.
2. Au. 2$$. 6istheaders no( fixed b4 scrollin throuh a list.
3$. 5un. 2$$. Added a uestboo#. Please lea,e 4our comments here.
2.. 5un. 2$$. Updated to ZKoss ,ersion 3.6.2. He( ra4 theme 1plomo.>ar1 from hereE !than#s to >lcasas&
httpEFF(((."#oss.orFforumFlistCommentF6.2'F
11. 5un. 2$$. Updated to ZKoss ,ersion 3.6.2.
15. 2ai. 2$$. Updated to ZKoss ,ersion 3.6.1.
12. 2ai. 2$$. All listboxes are no( (or#in (ith pain and sortin described in our smalltal#. !ZPerformance[ Pain and 7ortin
(ith a @ilter 8b>ect& 6in#E httpEFFdocs."#oss.orF(i#iFPainN7ortinN(ithNaNfilterNob>ect
12. 2ai. 2$$. :ein of the histor4.
Zksample2 Help to prevent the global warming by writing cool software. http:www.forstha!s.de

S-ar putea să vă placă și