Basics and Concepts of Java Server Faces
A standard approach to web- development
Martin Marinschek IRIAN Solutions GmbH (http:/ / www.irian.at) Submission ID 2220 2 AGENDA
1. Why JSF? 2. JSF – an introduction 3. Standard components of JSF 4. JSF – the LifeCycle 5. JSF Libraries and Add- On Frameworks 6. Outlook to the future of JSF 3 AGENDA
1. Why JSF? 2. JSF – an introduction 3. Standard components of JSF 4. JSF – the LifeCycle 5. JSF Libraries and Add- On Frameworks 6. Outlook to the future of JSF Java and its Standards! 4 1995 199619971998199920002001200220032004200520062007
JSP Standard Tag Library (JSTL)
1.0 1.1 1.2 JavaServer Pages (JSP)
0.92 1.0/ 1.1 1.2 2.0 2.1
Java- Servlets
1.0 2.0 2.1/ 2.2 2.3 2.4 2.5
Java
1.0 1.1 1.2 1.3 1.4 5.0 6.0 5 Why JSF?
Rendering was already standardized > JSP, Servlets, JSTL
Two- way- binding and form- handling missing
A host of frameworks filled this GAP Ja va- Web- Frameworks 6 WebOnSwing Swinglets JPublishEcho Millstone JSPWidget JoSssporing MVC Wicket DWR Sofia WebworkJucas Maverick VRaptor Struts Japple Stripes AnvGil WT Barracuda CocoonJAT TRaIFpEestry Verge JaffOapenXava ChrysSawliisngWeb http:/ / www.java- source.net/ open- source/ web- frameworks Java and its Standards! 7 1995 199619971998199920002001200220032004200520062007
JavaServer Faces (JSF)
1.0/ 1.1 1.2 JSP Standard Tag Library (JSTL)
1.0 1.1 1.2 JavaServer Pages (JSP)
0.92 1.0/ 1.1 1.2 2.0 2.1
Java- Servlets
1.0 2.0 2.1/ 2.2 2.3 2.4 2.5
Java
1.0 1.1 1.2 1.3 1.4 5.0 6.0 8 AGENDA
1. Why JSF? 2. JSF – an introduction 3. JSF – the LifeCycle 4. Standard components of JSF 5. JSF Libraries and Add- On Frameworks 6. Outlook to the future of JSF 9 JSF in a nutshell
• JSF is a … • ... new framework for building highly interactive web- apps with a simple and clear role- model • ... component- based framework • ... event- driven framework • … stateful framework on top of stateless protocols • ... RAD (Rapid Application Development) enabling platform • ... JCP standard! 10 Component driven framework
• JSF has built- in components • connect components inside a view- definition- file • (JSP, Facelets,..) • the ‚rendering‘ transforms these to markup like (X)HTML
Event driven framework registers at
triggers Event- Event- Source Listener
creates
Event sent to 12 JSF – a technology in wide use
IRIAN.at- JSF- Projects: > Deutsche Bank > Continentale > IPI.ch > OeKB > ICW AG > Erste Bank > Raiffeisen Capital Management Other JSF- Projects in Switzerland (we know of): > Credit Suisse If you have one, come to the Swiss JSF- user group meeting today in the evening! > More information at the end of this presentation… Apache MyFaces > „Companies using Apache MyFaces“ http:/ / wiki.apache.org/ myfaces/ Companies_Using_MyFaces 13 A JSF – Hello World example
h:panelGrid
h:outputLabel h:inputTex t
h:commandButto n 14 A JSF page needs…
View- Template – e.g. JSP:
One or more Backing- Beans (Managed- Beans) public class MyBean {}
Configuration in faces-config.xml:
.. action="#{customer.send}"/>
public class Customer {
private String firstname = null; private String secondname = null; //getter and setter
public String send(){ //back-end access (e.g. BusinessDelegate) return "fine"; } } 17 Faces- config.xml – Hello World
> Why JSF? > JSF – an introduction > Standard components of JSF > JSF – the LifeCycle > JSF Libraries and Add- On Frameworks > Outlook to the future of JSF 19 standard components - Text
• output of text - outputText
• commandLink
• Linking to websites/ web- apps outside of JSF:
• Caution: state gets lost, since this is not a postback
• HTTP parameters
• best for presenting structured data (like java.util.List) • horizontal: every column is defined by a UIColumn component • vertical: each row represents one item of the structured data • Facets (
setPropertyActionListener (preparation) navigation Item 25 Switching Master- Detail - Code
That‘s it:
• Label for a component:
value="#{bean.labelText}"/> Apache MyFaces Tomahawk: • label text can be used in message • use SelectOneMenu for choosing gender of a person: Person.java: private String gender; //getter+setter private List genderItems; public List getGenderItems(){ if(genderItems == null){ genderItems = new ArrayList(); genderItems.add(new SelectItem("m","male",null)); genderItems.add(new SelectItem("w","female",null)); } return genderItems; } 30 MyFaces Tomahawk: t:selectItems Select- Item- List could also be created automatically: > Why JSF? > JSF – an introduction > Standard components of JSF > JSF – the LifeCycle > JSF Libraries and Add- On Frameworks > Outlook to the future of JSF 32 JSF Request Lifecyle Response complete Apply Conversion Faces Restore Process request Request and View Events Response Values Validation P e r complete v o T e c n e N Render Response t s s s E I Response Response U M L complete complete p o d C d a e t e l Faces Render Process Invoke Process respons e Response Events Application Events Conversion Errors Render Response Validation / Conversion Errors Render Response 33 JSF Lifecycle – Initialization Apply Conversion Faces Restore Process request Request and View Events Values Validation P e r v o T e c n e N t s No view available s s E I U M L p o d C d a e t e l Faces Render Process Invoke Process respons e Response Events Application Events Create View 34 JSF Lifecycle – Validation fails Apply Conversion Faces Restore Process request Request and View Events Values Validation P e r v o T e c n e N t s s s E I U M L p o d C d a e t e l Faces Render Process Invoke Process respons e Response Events Application Events Validation / Conversion Errors Render Response JSF Lifecycle – Input Values 35 same way validation error validation ok a) If UICom.submittedValue = = null - > use ManagedBean.attribute 36 PhaseListener - configuration • JSF provides a special listener for the lifecycle • PhaseListener executed at the beginning and at the end of a phase. • register in faces- config.xml: public void afterPhase(PhaseEvent event){ System.out.println("afterPhase"); } public PhaseId getPhaseId(){ return PhaseId.ANY_PHASE; // return PhaseId.INVOKE_APPLICATION; } } 38 AGENDA > Why JSF? > JSF – an introduction > Standard components of JSF > JSF – the LifeCycle > JSF Libraries and Add- On Frameworks > Outlook to the future of JSF J SF – implementations and add- on 39 fIrmapmlemeewntoatrioknss > Sun RI > Apache MyFaces (founded by Thomas Spiegl and Manfred Geiler, both IRIAN.at) Extensions/ other frameworks on top of the standard > Apache MyFaces orchestra (glue code for JSF – Spring – JPA, conversation support) > Facelets (view definition language) > TrAccess (translation and accessibility) > Apache Shale (jsf goodies) > Ajax4JSF (ajax support) > JBoss Seam (persistence, jsf goodies) J SF – component- libraries 40 3rd party UI- component libraries > MyFaces Trinidad (formerly Oracle ADF Faces) > MyFaces Rich Client Framework (coming soon, donation by Oracle) > MyFaces Tomahawk, Tomahawk Sandbox > MyFaces Tobago > ICE Faces > Rich Faces > Backbase 41 AGENDA > Why JSF? > JSF – an introduction > Standard components of JSF > JSF – the LifeCycle > JSF Libraries and Add- On Frameworks > Outlook to the future of JSF 42 JSF Future Integration of Facelets (or something like Facelets) > easier templating > lightweight components Integration of AJAX > make the life- cycle AJAX- aware > include a basic client- side API > similar to the jsf- extensions- project State- Saving > Make stateless components the default > Allow GET- support in JSF (passing some of the state) Diverse stuff: > Annotation support > Validation: form- level and inter- component validation > Better Error- Handling 43 JSF User Group meeting Switzerland Initial meeting: Today, 17:30 – open end… > Credit Suisse Zürich- Uetlihof > Pausenzone 10. Etage > Uetlibergstrasse 231; 8045 Zürich > Starring: – Ed Burns, JSF spec lead – Alexander Jesse, designated JSF user group Switzerland president > Free beer ;) ! 44 Links and books JSF Books – “JSF@Work” (German) by Martin Marinschek – “JSF – the complete Reference” by Ed Burns – „JSF in Action“ by Kito D. Mann – „JavaServer Faces“ by Hans Bergsten – „Core JSF“ by David Geary JSF Web Resources – JSFCentral.com – jamesholmes.com/ javaserverfaces – myfaces.apache.org We love Swiss chocolate! Martin Marinschek http:/ / www.irian.at/ IRIAN Solutions GmbH [email protected] MyFaces founders Expert group members: JSF 2.0 Web- Beans JSF- Metadata JSF- Portlet- Bridge experienced JSF trainers and developers http:/ / www.irian.at/