SlideShare ist ein Scribd-Unternehmen logo
1 von 44
Downloaden Sie, um offline zu lesen
JSF 2
                             par la pratique




                                    1
vendredi 10 septembre 2010
INTERVENANT
                      Damien GOUYETTE




          Expert technique java / JEE. 
          Scrummaster certifié

          Plus particulièrement spécialisé dans le développement d'IHM web
          Blog : http://www.cestpasdur.com
          Twitter : @cestpasdur
                                                2
vendredi 10 septembre 2010
OBJECTIFS DE LA
                             PRÉSENTATION


         • Présenter         les nouveautés de JSF 2

         • Donner   des exemples concrets d’utilisation au travers du
             développement d’un blog




                                              3
vendredi 10 septembre 2010
Historique



         • 2004              : JSF 1.0 & 1.1

         • 2006              : JSF 1.2

         • Octobre               2009 : JSF 2



                                                4
vendredi 10 septembre 2010
PLAN DU BLOG




                                  5
vendredi 10 septembre 2010
DÉCOUPAGE D’UNE PAGE




                             6
vendredi 10 septembre 2010
FONCTIONNALITÉS DE
                           FACELET

    • Templating              & inclusion,

    • Création               de composant,

    • Débogage,

    • Répétition.



                                             7
vendredi 10 septembre 2010
CODE DU MAITRE




                                   8
vendredi 10 septembre 2010
UN PEU DE TRAITEMENT




                             9
vendredi 10 septembre 2010
JSF2 & ANNOTATIONS

    • @ManagedBean

    • @FacesComponent,

    • @FacesRenderer,

    • @FacesConverter,

    • @FacesValidator.


                                     10
vendredi 10 septembre 2010
MANAGEDBEAN &
                              ANNOTATION

              • @ApplicationScoped,

              • @SessionScoped,

              • @ViewScoped    (new),
              • @RequestScoped

              • @NoneScoped,



                                        11
vendredi 10 septembre 2010
UN PEU DE NAVIGATION




                             12
vendredi 10 septembre 2010
NAVIGATION : AVANT/APRÈS




                             13
vendredi 10 septembre 2010
NAVIGATION
                   CONDITIONNELLE <IF/>




      <if>#{managedBean.proprieteBooleenne}</if>

                             14
vendredi 10 septembre 2010
AJOUT D’UN COMMENTAIRE




                             15
vendredi 10 septembre 2010
PROBLÈME DE DOUBLE
                          SOUMISSION



    • Solution               : GET




                                     16
vendredi 10 septembre 2010
REDIRECTION AVEC JSF 2



    • Outcome                suffixé par ?faces-redirect=true

    •<redirect/> dans navigation-rule



                                             17
vendredi 10 septembre 2010
EXEMPLES :

    •?faces-redirect=true en suffixe des outcome




    •<redirect/>
        sur la navigation-case



                                 18
vendredi 10 septembre 2010
URL BOOKMARKABLES




                                19
vendredi 10 septembre 2010
BOOKMARK & JSF


    •3       composants :

         • <h:link/>

         • <h:button/>

         • <f:viewParam/>



                                   20
vendredi 10 septembre 2010
BOOKMARK & CODE




                                    21
vendredi 10 septembre 2010
AFFICHAGE D’UNE
                              NOTIFICATION




                                    22
vendredi 10 septembre 2010
FLASHSCOPE




                                 23
vendredi 10 septembre 2010
VALIDATION DU
                             COMMENTAIRE




                                   24
vendredi 10 septembre 2010
VALIDATION : AVANT




                                     25
vendredi 10 septembre 2010
VALIDATION : APRÈS




                                     26
vendredi 10 septembre 2010
ANNOTATIONS DISPONIBLES


        Contraintes disponibles :

    • @CreditCardNumber, @Email, @URL

    • @Length, @Range, @Min, @Max,

    •    @Past, @Future...


                               27
vendredi 10 septembre 2010
AJOUT D’UN COMMENTAIRE
                EN AJAX




                             28
vendredi 10 septembre 2010
<F:AJAX/> ATTRIBUTS

        execute & render, valeurs possibles :

        @all,
        @none,
        @form,
        @this (par défaut)

        event
         change, click...
                                      29
vendredi 10 septembre 2010
LE CODE




                                30
vendredi 10 septembre 2010
VALIDATION & AJAX
    • Valide            le contenu à chaque perte de focus sur un élément.




                                              31
vendredi 10 septembre 2010
VALIDATION & AJAX 2




                                      32
vendredi 10 septembre 2010
COMPOSANT COMPOSITE
                   TWITTER



    • Nécessite              l’ajout de ressources statiques




                                                 33
vendredi 10 septembre 2010
TRAITEMENT DES
                                 RESSOURCES
    •   CSS, javascript, images
    •   Emplacements
         •   /resources
         •   /META-INF/resources
    •   Structure des resources
         •   [localePrefix]/[libraryName]/[libraryVersion]/resourceName/[resourceVersion]
         •   [] = facultatif
         •   EL : #{resource['<library name>:<resource name>']} (utilisable aussi dans les fichiers JS et CSS)
    •   Version
         •   La dernière version disponible (library & resource) est sélectionnée automatiquement


                                                         34
vendredi 10 septembre 2010
TRAITEMENT DES
                               RESSOURCES




    •   <h:outputScript library="helloworld" name="function.js" target="head"/>
        ou #{resource["helloworld:function.js"]}
                                         35
vendredi 10 septembre 2010
LE CODE




                                36
vendredi 10 septembre 2010
COMPOSITE COMPONENT ET
        BACKING BEAN
        Associer du code métier java au composant composite

        Backing Bean :

        implements javax.faces.component.NamingContainer

        getFamily() return «javax.faces.component.NamingContainer»




                                    37
vendredi 10 septembre 2010
COMPOSITE COMPONENT ET
        BACKING BEAN




                             38
vendredi 10 septembre 2010
COMPOSITE COMPONENT ET
        BACKING BEAN




                             39
vendredi 10 septembre 2010
AMÉLIORATION DES
                              PERFORMANCES


    • ViewState,

    • Ajax




                                    40
vendredi 10 septembre 2010
PRÊTS POUR JSF2

      Librairies de composants
      • Richfaces 4.0 M2, IceFaces 2.0 béta 1, PrimeFaces 2.0...
      Serveurs d'application
      • Glassfish, Jboss, Tomcat, Jetty
      IDE
      • NetBeans 6.9, Eclipse et JbossTools 3.2 M1,
      • IntelliJ IDEA...
    • Génération de code : Archetypes Maven, Richfaces CDK
                                    41
vendredi 10 septembre 2010
SYNTHÈSE DES NOUVEAUTÉS

                             Nouvelles fonctionnalités               Simplifications
                              Ajax inclus et optimisé     Développement de composant facilité
                                Profils d’utilisation              Navigation simplifiée

                                                           Remplacement de la configuration
                Externalisation de ressources statiques
                                                              XML par des annotations

                   Nouveaux scopes : ViewScope et
                             FlashScope


                   Support de GET en plus du POST



                                                           42
vendredi 10 septembre 2010
POUR ALLER + LOIN

    •   Code source : http://github.com/dgouyette/jugsummercamp

    •   Refcard JSF2 : http://refcardz.dzone.com/refcardz/javaserver-faces-20

    •   Le site de la spécification JSR-314 : http://jcp.org/en/jsr/detail?id=314

    •   Blog Ed Burns, un des spec leader : http://www.java.net/blogs/edburns

    •   Liste des librairies tierces-parties : http://www.jsfmatrix.net/

    •   Livre : JavaServerFaces 2: the complete reference

    •   Le livre d'Antonio Goncalves sur JEE 6 en général: « Beginning Java EE 6 platform with Glassfish

                                                           43
vendredi 10 septembre 2010
QUESTIONS / RÉPONSES


                             44
vendredi 10 septembre 2010

Weitere ähnliche Inhalte

Andere mochten auch

Andere mochten auch (20)

Spring MVC
Spring MVCSpring MVC
Spring MVC
 
Spring 3 MVC CodeMash 2009
Spring 3 MVC   CodeMash 2009Spring 3 MVC   CodeMash 2009
Spring 3 MVC CodeMash 2009
 
Spring Framework - Validation
Spring Framework - ValidationSpring Framework - Validation
Spring Framework - Validation
 
3 Jsf
3 Jsf3 Jsf
3 Jsf
 
Spring MVC framework
Spring MVC frameworkSpring MVC framework
Spring MVC framework
 
Presentation Spring, Spring MVC
Presentation Spring, Spring MVCPresentation Spring, Spring MVC
Presentation Spring, Spring MVC
 
Spring Web MVC
Spring Web MVCSpring Web MVC
Spring Web MVC
 
Spring MVC Basics
Spring MVC BasicsSpring MVC Basics
Spring MVC Basics
 
Java Server Faces (JSF) - Basics
Java Server Faces (JSF) - BasicsJava Server Faces (JSF) - Basics
Java Server Faces (JSF) - Basics
 
Servlets et JSP
Servlets et JSPServlets et JSP
Servlets et JSP
 
Java Server Faces (JSF)
Java Server Faces (JSF)Java Server Faces (JSF)
Java Server Faces (JSF)
 
Spring MVC 3.0 Framework
Spring MVC 3.0 FrameworkSpring MVC 3.0 Framework
Spring MVC 3.0 Framework
 
J2EE vs .NET
J2EE vs .NETJ2EE vs .NET
J2EE vs .NET
 
Document
DocumentDocument
Document
 
Logique 1 Logiciel Controle De Gestion
Logique 1 Logiciel Controle De GestionLogique 1 Logiciel Controle De Gestion
Logique 1 Logiciel Controle De Gestion
 
Presentation Marche Logiciel
Presentation Marche LogicielPresentation Marche Logiciel
Presentation Marche Logiciel
 
Rapport Etat des lieux_MECNDD TOME II_VF
Rapport Etat des lieux_MECNDD TOME II_VFRapport Etat des lieux_MECNDD TOME II_VF
Rapport Etat des lieux_MECNDD TOME II_VF
 
Presentation Web2 2010
Presentation Web2 2010Presentation Web2 2010
Presentation Web2 2010
 
Les Points Clés De La Formation Um
Les Points Clés De La Formation UmLes Points Clés De La Formation Um
Les Points Clés De La Formation Um
 
151202 arbre etonnant-en_afrique_du_sud__ch1
151202   arbre etonnant-en_afrique_du_sud__ch1151202   arbre etonnant-en_afrique_du_sud__ch1
151202 arbre etonnant-en_afrique_du_sud__ch1
 

JSF2 par la pratique

  • 1. JSF 2 par la pratique 1 vendredi 10 septembre 2010
  • 2. INTERVENANT Damien GOUYETTE Expert technique java / JEE.  Scrummaster certifié Plus particulièrement spécialisé dans le développement d'IHM web Blog : http://www.cestpasdur.com Twitter : @cestpasdur 2 vendredi 10 septembre 2010
  • 3. OBJECTIFS DE LA PRÉSENTATION • Présenter les nouveautés de JSF 2 • Donner des exemples concrets d’utilisation au travers du développement d’un blog 3 vendredi 10 septembre 2010
  • 4. Historique • 2004 : JSF 1.0 & 1.1 • 2006 : JSF 1.2 • Octobre 2009 : JSF 2 4 vendredi 10 septembre 2010
  • 5. PLAN DU BLOG 5 vendredi 10 septembre 2010
  • 6. DÉCOUPAGE D’UNE PAGE 6 vendredi 10 septembre 2010
  • 7. FONCTIONNALITÉS DE FACELET • Templating & inclusion, • Création de composant, • Débogage, • Répétition. 7 vendredi 10 septembre 2010
  • 8. CODE DU MAITRE 8 vendredi 10 septembre 2010
  • 9. UN PEU DE TRAITEMENT 9 vendredi 10 septembre 2010
  • 10. JSF2 & ANNOTATIONS • @ManagedBean • @FacesComponent, • @FacesRenderer, • @FacesConverter, • @FacesValidator. 10 vendredi 10 septembre 2010
  • 11. MANAGEDBEAN & ANNOTATION • @ApplicationScoped, • @SessionScoped, • @ViewScoped (new), • @RequestScoped • @NoneScoped, 11 vendredi 10 septembre 2010
  • 12. UN PEU DE NAVIGATION 12 vendredi 10 septembre 2010
  • 13. NAVIGATION : AVANT/APRÈS 13 vendredi 10 septembre 2010
  • 14. NAVIGATION CONDITIONNELLE <IF/> <if>#{managedBean.proprieteBooleenne}</if> 14 vendredi 10 septembre 2010
  • 15. AJOUT D’UN COMMENTAIRE 15 vendredi 10 septembre 2010
  • 16. PROBLÈME DE DOUBLE SOUMISSION • Solution : GET 16 vendredi 10 septembre 2010
  • 17. REDIRECTION AVEC JSF 2 • Outcome suffixé par ?faces-redirect=true •<redirect/> dans navigation-rule 17 vendredi 10 septembre 2010
  • 18. EXEMPLES : •?faces-redirect=true en suffixe des outcome •<redirect/> sur la navigation-case 18 vendredi 10 septembre 2010
  • 19. URL BOOKMARKABLES 19 vendredi 10 septembre 2010
  • 20. BOOKMARK & JSF •3 composants : • <h:link/> • <h:button/> • <f:viewParam/> 20 vendredi 10 septembre 2010
  • 21. BOOKMARK & CODE 21 vendredi 10 septembre 2010
  • 22. AFFICHAGE D’UNE NOTIFICATION 22 vendredi 10 septembre 2010
  • 23. FLASHSCOPE 23 vendredi 10 septembre 2010
  • 24. VALIDATION DU COMMENTAIRE 24 vendredi 10 septembre 2010
  • 25. VALIDATION : AVANT 25 vendredi 10 septembre 2010
  • 26. VALIDATION : APRÈS 26 vendredi 10 septembre 2010
  • 27. ANNOTATIONS DISPONIBLES Contraintes disponibles : • @CreditCardNumber, @Email, @URL • @Length, @Range, @Min, @Max, • @Past, @Future... 27 vendredi 10 septembre 2010
  • 28. AJOUT D’UN COMMENTAIRE EN AJAX 28 vendredi 10 septembre 2010
  • 29. <F:AJAX/> ATTRIBUTS execute & render, valeurs possibles : @all, @none, @form, @this (par défaut) event change, click... 29 vendredi 10 septembre 2010
  • 30. LE CODE 30 vendredi 10 septembre 2010
  • 31. VALIDATION & AJAX • Valide le contenu à chaque perte de focus sur un élément. 31 vendredi 10 septembre 2010
  • 32. VALIDATION & AJAX 2 32 vendredi 10 septembre 2010
  • 33. COMPOSANT COMPOSITE TWITTER • Nécessite l’ajout de ressources statiques 33 vendredi 10 septembre 2010
  • 34. TRAITEMENT DES RESSOURCES • CSS, javascript, images • Emplacements • /resources • /META-INF/resources • Structure des resources • [localePrefix]/[libraryName]/[libraryVersion]/resourceName/[resourceVersion] • [] = facultatif • EL : #{resource['<library name>:<resource name>']} (utilisable aussi dans les fichiers JS et CSS) • Version • La dernière version disponible (library & resource) est sélectionnée automatiquement 34 vendredi 10 septembre 2010
  • 35. TRAITEMENT DES RESSOURCES • <h:outputScript library="helloworld" name="function.js" target="head"/> ou #{resource["helloworld:function.js"]} 35 vendredi 10 septembre 2010
  • 36. LE CODE 36 vendredi 10 septembre 2010
  • 37. COMPOSITE COMPONENT ET BACKING BEAN Associer du code métier java au composant composite Backing Bean : implements javax.faces.component.NamingContainer getFamily() return «javax.faces.component.NamingContainer» 37 vendredi 10 septembre 2010
  • 38. COMPOSITE COMPONENT ET BACKING BEAN 38 vendredi 10 septembre 2010
  • 39. COMPOSITE COMPONENT ET BACKING BEAN 39 vendredi 10 septembre 2010
  • 40. AMÉLIORATION DES PERFORMANCES • ViewState, • Ajax 40 vendredi 10 septembre 2010
  • 41. PRÊTS POUR JSF2 Librairies de composants • Richfaces 4.0 M2, IceFaces 2.0 béta 1, PrimeFaces 2.0... Serveurs d'application • Glassfish, Jboss, Tomcat, Jetty IDE • NetBeans 6.9, Eclipse et JbossTools 3.2 M1, • IntelliJ IDEA... • Génération de code : Archetypes Maven, Richfaces CDK 41 vendredi 10 septembre 2010
  • 42. SYNTHÈSE DES NOUVEAUTÉS Nouvelles fonctionnalités Simplifications Ajax inclus et optimisé Développement de composant facilité Profils d’utilisation Navigation simplifiée Remplacement de la configuration Externalisation de ressources statiques XML par des annotations Nouveaux scopes : ViewScope et FlashScope Support de GET en plus du POST 42 vendredi 10 septembre 2010
  • 43. POUR ALLER + LOIN • Code source : http://github.com/dgouyette/jugsummercamp • Refcard JSF2 : http://refcardz.dzone.com/refcardz/javaserver-faces-20 • Le site de la spécification JSR-314 : http://jcp.org/en/jsr/detail?id=314 • Blog Ed Burns, un des spec leader : http://www.java.net/blogs/edburns • Liste des librairies tierces-parties : http://www.jsfmatrix.net/ • Livre : JavaServerFaces 2: the complete reference • Le livre d'Antonio Goncalves sur JEE 6 en général: « Beginning Java EE 6 platform with Glassfish 43 vendredi 10 septembre 2010
  • 44. QUESTIONS / RÉPONSES 44 vendredi 10 septembre 2010