••
                                            ••
                                                 ••
                                                      ••




                                                                                           What is JSF?
                                                           ••
                                                                ••
                                                                     ••
                                                                          •••
                                                                                ••••
                                                                                       •••••••••


  What is JSF?



                             Roosendaal - 22/09/2005

                             Gie Indesteege - ABIS Training & Consulting

                             gindesteege@abis.be




ABIS Training & Consulting                                                        1
JavaServer Faces (JSF)




                                 What is JSF?
• Web frameworks
• JSF terminology
• JSF life cycle
• Web development with JSF
• Q&A




What is JSF?                 2
Web frameworks




                                                                 What is JSF?
Strong requirements needed for e-business applications:
    scalability, availability, security, flexibility, ...

No chances taken -> use reliable, well supported framework
• separation of concerns
• layering
• container/component
• extensible
• active community/active development
• standards based




What is JSF?                                                 3
Model View Controller framework




                                                                                  What is JSF?
                          Request
                                       Servlet
               Browser

                                           Controller

                                                                Logic

                                                   JavaBean             EIS
                    Response

                                     JSP                Model


                                    View


• Controller servlet regulates navigation
• JavaBean provides/accesses business logic
• JavaServer Page (JSP) creates presentation/view

What is JSF?                                                                  4
JSF goes beyond MVC (model 2)




                                                                                           What is JSF?
                                                        invoke
                                   FacesServlet                  action method




                           t
                          es
                     qu
                    re
                                                  faces-



                                     select
                                                config.xml
          Browser                                                                EIS
                                                                   JavaBean
                    res
                         po
                           ns
                               e
                                              JSP




• mainly view framework
• obtain configuration from external source (i.e. XML file)
• use Request Handlers as Commands to delegate control

What is JSF?                                                                           5
JSF architecture




                            What is JSF?
(JSF 1.0)




API’s
• JSF (javax.faces.*)
• JSTL
• Apache Commons

What is JSF?            6
JSF framework




                                                                         What is JSF?
Important characteristics:
• stateful UI component model
    - separation of presentation (rendering),
        mark-up generation (HTML, WML, XML, ...)
    - and business logic -> integration with model objects (JavaBeans)
• processing of client-side events (at server side)
• extensible type conversion system
• form handling and validation




What is JSF?                                                         7
Advantages of JSF




                                                                           What is JSF?
• official Java standard JSF 1.0 - JSR 127
        JSR 252: JavaServer Faces 1.2 - Proposed Final Draft (22/8/2005)
• easier to create multi-channel architectures
    - not restricted to JSP (HTML)
• event handling (server side)
• Swing-like GUI creation possible
• Internationalisation


http://java.sun.com/j2ee/javaserverfaces/




What is JSF?                                                           8
JavaServer Faces (JSF)




                                 What is JSF?
• Web frameworks
• JSF terminology
• JSF life cycle
• Web development with JSF
• Q&A




What is JSF?                 9
JSF terminology




                                                                   What is JSF?
Faces servlet
    - controller servlet, part of the JSF framework

Faces configuration (faces-config.xml)
    - configuration of web application under control of JSF
    - (page) navigation rules
    - managed beans (bean under control of JSF framework)

Faces JavaServer Pages
    - special tag libraries (core, html, ...)
    - faces expression language




What is JSF?                                                  10
JSF terminology (cont.)




                                                                       What is JSF?
Faces (UI) components
    - standard set of graphical widgets and controls (stateful)
    - based on JavaBeans
    - associated with renderer
    - organised in tree structure (per JSP)




What is JSF?                                                      11
JavaServer Faces (JSF)




                                  What is JSF?
• Web frameworks
• JSF terminology
• JSF life cycle
• Web development with JSF
• Q&A




What is JSF?                 12
JSF life cycle




                                                  What is JSF?
There are 6 phases in the JSF life cycle:
• Reconstitute request tree (restore view)
• Apply request values
• Process validations
• Update model values
• Invoke application
• Render response




What is JSF?                                 13
JSF life cycle (part 1)




                                               What is JSF?
No application data passed

                         JSF Framework

                            Restore
               Request       view


                                no data


                            Render
          Response         response




What is JSF?                              14
JSF life cycle (part 2)




                                                                         What is JSF?
Use of (HTML) form data

                          JSF Framework

                             Restore       ...
                Request       view


                                 no data


                                                       Update
                             Render        ...         model
               Response     response
                                                       values




UI components organised in hierarchical tree per JSP

bind input fields to business data in backing bean (managed bean)


What is JSF?                                                        15
JSF life cycle (part 3)




                                                                        What is JSF?
Navigation between pages (static vs. dynamic)
                          JSF Framework

                             Restore            ...
                Request       view


                                 no data


                                                          Update
                             Render           Invoke
                                                          model
               Response     response        application
                                                          values




rules in configuration file (faces-config.xml)
<navigation-rule>
  <from-view-id>/index.jsp</from-view-id>
  <navigation-case>
   <from-outcome>success</from-outcome>
   <to-view-id>/welcome.jsp</to-view-id>
  </navigation-case>


What is JSF?                                                       16
JSF life cycle (part 4)




                                                                                                  What is JSF?
Validation

                          JSF Framework

                                           Apply
                              Restore                              Process
                                          request
                Request        view                               validations
                                           values
                           no data                                     validation
                                                                         error

                                                                                    Update
                              Render                  Invoke
                                                                                    model
               Response      response               application
                                                                                    values




• syntax -> faces validators working on data in UI components
• business -> logic accessing model values in managed beans

Error messages via FacesMessage objects and special tags in JSP

What is JSF?                                                                                 17
JSF life cycle (final)




                                                                                                           What is JSF?
Event handling
                                 JSF Framework

                                                    Apply request values     Process validations
                                     Restore
                                                                                        PVE
                Request               view
                                                      PVE          AE
                                                                             immediate input
                                          no data      immediate command             convervion/
                                                                                   validation error

                                                      Invoke application
                                     Render                                          Update model
                                                              AE
               Response             response                                            values




                 PVE                                            AE
                          C   V VCL(n) VCL(a)                              AL(n)     AL(a)        A


• action events - when a command is pressed (button or link)
• process validation events- when value of an input field has changed
• input events - immediate commands - immediate input
• (pre- and post) phase events

What is JSF?                                                                                          18
JavaServer Faces (JSF)




                                  What is JSF?
• Web frameworks
• JSF terminology
• JSF life cycle
• Web development with JSF
• Q&A




What is JSF?                 19
Web development with JSF




                                                                        What is JSF?
JSF application consists of:
• JSP pages
• UI components represented as stateful objects on the server
• a custom tag library for rendering UI components
• a custom tag library for representing event handlers and validators
• JavaBeans (or model objects) containing application-specific func-
  tionality and data
• event listeners
• server-side helper classes
• validators, event handlers, and navigation handlers
• application configuration resource file faces-config.xml




What is JSF?                                                       20
Web development with JSF




                                                           What is JSF?
Native

Supported by IDE
• IBM WebSphere Studio and Rational Developer
• Sun Java Studio Creator
• Borland JBuilder
• Oracle JDeveloper
• ...

or

Integration of JSF with EGL (see next presentation)




What is JSF?                                          21
JavaServer Faces (JSF)




                                  What is JSF?
• Web frameworks
• JSF terminology
• JSF life cycle
• Web development with JSF
• Q&A




What is JSF?                 22
JavaServer Faces (JSF)




                                              What is JSF?
                             Thank you




Gie Indesteege

ABIS Training & Consulting




What is JSF?                             23

JSF-Starter

  • 1.
    •• •• •• •• What is JSF? •• •• •• ••• •••• ••••••••• What is JSF? Roosendaal - 22/09/2005 Gie Indesteege - ABIS Training & Consulting gindesteege@abis.be ABIS Training & Consulting 1
  • 2.
    JavaServer Faces (JSF) What is JSF? • Web frameworks • JSF terminology • JSF life cycle • Web development with JSF • Q&A What is JSF? 2
  • 3.
    Web frameworks What is JSF? Strong requirements needed for e-business applications: scalability, availability, security, flexibility, ... No chances taken -> use reliable, well supported framework • separation of concerns • layering • container/component • extensible • active community/active development • standards based What is JSF? 3
  • 4.
    Model View Controllerframework What is JSF? Request Servlet Browser Controller Logic JavaBean EIS Response JSP Model View • Controller servlet regulates navigation • JavaBean provides/accesses business logic • JavaServer Page (JSP) creates presentation/view What is JSF? 4
  • 5.
    JSF goes beyondMVC (model 2) What is JSF? invoke FacesServlet action method t es qu re faces- select config.xml Browser EIS JavaBean res po ns e JSP • mainly view framework • obtain configuration from external source (i.e. XML file) • use Request Handlers as Commands to delegate control What is JSF? 5
  • 6.
    JSF architecture What is JSF? (JSF 1.0) API’s • JSF (javax.faces.*) • JSTL • Apache Commons What is JSF? 6
  • 7.
    JSF framework What is JSF? Important characteristics: • stateful UI component model - separation of presentation (rendering), mark-up generation (HTML, WML, XML, ...) - and business logic -> integration with model objects (JavaBeans) • processing of client-side events (at server side) • extensible type conversion system • form handling and validation What is JSF? 7
  • 8.
    Advantages of JSF What is JSF? • official Java standard JSF 1.0 - JSR 127 JSR 252: JavaServer Faces 1.2 - Proposed Final Draft (22/8/2005) • easier to create multi-channel architectures - not restricted to JSP (HTML) • event handling (server side) • Swing-like GUI creation possible • Internationalisation http://java.sun.com/j2ee/javaserverfaces/ What is JSF? 8
  • 9.
    JavaServer Faces (JSF) What is JSF? • Web frameworks • JSF terminology • JSF life cycle • Web development with JSF • Q&A What is JSF? 9
  • 10.
    JSF terminology What is JSF? Faces servlet - controller servlet, part of the JSF framework Faces configuration (faces-config.xml) - configuration of web application under control of JSF - (page) navigation rules - managed beans (bean under control of JSF framework) Faces JavaServer Pages - special tag libraries (core, html, ...) - faces expression language What is JSF? 10
  • 11.
    JSF terminology (cont.) What is JSF? Faces (UI) components - standard set of graphical widgets and controls (stateful) - based on JavaBeans - associated with renderer - organised in tree structure (per JSP) What is JSF? 11
  • 12.
    JavaServer Faces (JSF) What is JSF? • Web frameworks • JSF terminology • JSF life cycle • Web development with JSF • Q&A What is JSF? 12
  • 13.
    JSF life cycle What is JSF? There are 6 phases in the JSF life cycle: • Reconstitute request tree (restore view) • Apply request values • Process validations • Update model values • Invoke application • Render response What is JSF? 13
  • 14.
    JSF life cycle(part 1) What is JSF? No application data passed JSF Framework Restore Request view no data Render Response response What is JSF? 14
  • 15.
    JSF life cycle(part 2) What is JSF? Use of (HTML) form data JSF Framework Restore ... Request view no data Update Render ... model Response response values UI components organised in hierarchical tree per JSP bind input fields to business data in backing bean (managed bean) What is JSF? 15
  • 16.
    JSF life cycle(part 3) What is JSF? Navigation between pages (static vs. dynamic) JSF Framework Restore ... Request view no data Update Render Invoke model Response response application values rules in configuration file (faces-config.xml) <navigation-rule> <from-view-id>/index.jsp</from-view-id> <navigation-case> <from-outcome>success</from-outcome> <to-view-id>/welcome.jsp</to-view-id> </navigation-case> What is JSF? 16
  • 17.
    JSF life cycle(part 4) What is JSF? Validation JSF Framework Apply Restore Process request Request view validations values no data validation error Update Render Invoke model Response response application values • syntax -> faces validators working on data in UI components • business -> logic accessing model values in managed beans Error messages via FacesMessage objects and special tags in JSP What is JSF? 17
  • 18.
    JSF life cycle(final) What is JSF? Event handling JSF Framework Apply request values Process validations Restore PVE Request view PVE AE immediate input no data immediate command convervion/ validation error Invoke application Render Update model AE Response response values PVE AE C V VCL(n) VCL(a) AL(n) AL(a) A • action events - when a command is pressed (button or link) • process validation events- when value of an input field has changed • input events - immediate commands - immediate input • (pre- and post) phase events What is JSF? 18
  • 19.
    JavaServer Faces (JSF) What is JSF? • Web frameworks • JSF terminology • JSF life cycle • Web development with JSF • Q&A What is JSF? 19
  • 20.
    Web development withJSF What is JSF? JSF application consists of: • JSP pages • UI components represented as stateful objects on the server • a custom tag library for rendering UI components • a custom tag library for representing event handlers and validators • JavaBeans (or model objects) containing application-specific func- tionality and data • event listeners • server-side helper classes • validators, event handlers, and navigation handlers • application configuration resource file faces-config.xml What is JSF? 20
  • 21.
    Web development withJSF What is JSF? Native Supported by IDE • IBM WebSphere Studio and Rational Developer • Sun Java Studio Creator • Borland JBuilder • Oracle JDeveloper • ... or Integration of JSF with EGL (see next presentation) What is JSF? 21
  • 22.
    JavaServer Faces (JSF) What is JSF? • Web frameworks • JSF terminology • JSF life cycle • Web development with JSF • Q&A What is JSF? 22
  • 23.
    JavaServer Faces (JSF) What is JSF? Thank you Gie Indesteege ABIS Training & Consulting What is JSF? 23