Documentos de Académico
Documentos de Profesional
Documentos de Cultura
com-Support de la 25/01/2017
Formation Java Server Faces
Formation
JSF (Java Server Faces)
Fabien Brissonneau
Site : http://www.alphorm.com Consultant, concepteur et formateur
Blog : http://blog.alphorm.com Objets Logiciels
Formation Java Server Faces alphorm.com
Plan
Prsentation du formateur
Le plan de la formation
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 1
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Prsentation du formateur
Fabien Brissonneau
Email : fabien.brissonneau@gmail.com
Fondateur de eiXa6
Mes rfrences :
Mon profil LinkedIn : http://fr.linkedin.com/pub/fabien-brissonneau/65/902/92a/
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 2
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Le plan de la formation
Chapitre 1 : Lapplication Web
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 3
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Il ny a plus qu
Lapplication Web
Architecture
Fabien Brissonneau
Site : http://www.alphorm.com Consultant, concepteur et formateur
Blog : http://blog.alphorm.com Objets Logiciels
Formation Java Server Faces alphorm.com
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 4
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Plan
Les parties de lapplication
Un servlet
Un EJB
Une entit
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 5
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Le tlchargement est li
Glassfish, implmentation de rfrence pour les serveurs JEE
Tomcat, implmentation de rfrence pour la partie Web
Un servlet
Une classe hritant de HttpServlet
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 6
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Un EJB
Tout simplement un POJO, qui soccupe de traitement logiciel
Une entit
Une classe annote
Dclare une cl
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 7
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Ce quon a couvert
Les parties de lapplication
Un servlet
Un EJB
Une entit
Lapplication Web
Packaging et
dploiement
Fabien Brissonneau
Site : http://www.alphorm.com Consultant, concepteur et formateur
Blog : http://blog.alphorm.com Objets Logiciels
Formation Java Server Faces alphorm.com
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 8
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Plan
Fichiers war
Fichiers jar
Fichiers ear
Fichiers war
Le dploiement dune application Web est dcrit par un fichier
Structure prdfinie
La racine contient les fichiers textes, HTML, JSP, JSF
Un rpertoire WEB-INF qui contient les servlets et les classes Java
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 9
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Fichiers JAR
La partie modle est stocke dans un fichier dextension .jar
Fichiers EAR
Le fichier en extension ear regroupe les deux prcdents
Structure :
/META-INF
/MANIFEST.MF
/<fichier web>.war
/<fichier ejb>.jar
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 10
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Ce quon a couvert
Fichiers war
Fichiers jar
Fichiers ear
Lapplication Web
LAPI Servlet
Fabien Brissonneau
Site : http://www.alphorm.com Consultant, concepteur et formateur
Blog : http://blog.alphorm.com Objets Logiciels
Formation Java Server Faces alphorm.com
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 11
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Plan
Ce que fait un Servlet
Exemple dapplication
La classe HttpServlet
La classe ServletContext
La classe HttpSession
La classe RequestDispatcher
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 12
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Exemple dapplication
Une mthode doGet dun Servlet pour rcuprer des photos
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 13
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
La classe HttpServlet
Dans le package javax.servlet.http
La classe ServletContext
Dans le package javax.servlet
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 14
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
La classe HttpSession
Dans le package javax.servlet.http
Une instance unique par client, donc une map par client
La classe RequestDispatcher
Dans le package javax.servlet
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 15
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Ce quon a couvert
Ce que fait un Servlet
Exemple dapplication
La classe HttpServlet
La classe ServletContext
La classe HttpSession
La classe RequestDispatcher
Lapplication Web
Le mapping des
Servlets
Fabien Brissonneau
Site : http://www.alphorm.com Consultant, concepteur et formateur
Blog : http://blog.alphorm.com Objets Logiciels
Formation Java Server Faces alphorm.com
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 16
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Plan
Le dploiement des informations
Lannotation @WebServlet
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 17
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Lannotation @WebServlet
Paramtre asyncSupported (boolean)
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 18
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Ce quon a couvert
Le dploiement des informations
Lannotation @WebServlet
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 19
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Lapplication Web
Les pages JSP
Fabien Brissonneau
Site : http://www.alphorm.com Consultant, concepteur et formateur
Blog : http://blog.alphorm.com Objets Logiciels
Formation Java Server Faces alphorm.com
Plan
Larchitecture JSP
Exemple de JSP
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 20
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Larchitecture JSP
Une page JSP est une page HTML dans laquelle apparaissent des balises
introduisant du Java
L o le Servlet tait du Java retournant du HTML
Exemple de JSP
Une page dextension .jsp par dfaut, la racine de lapplication
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 21
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 22
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 23
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 24
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Taglib
Avec uri pour spcifier le nom du fichier
Avec prefix pour spcifier le prfixe xml
Ce quon a couvert
Larchitecture JSP
Exemple de JSP
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 25
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Lapplication Web
JSP et Javabeans
Fabien Brissonneau
Site : http://www.alphorm.com Consultant, concepteur et formateur
Blog : http://blog.alphorm.com Objets Logiciels
Formation Java Server Faces alphorm.com
Plan
Dfinition des JavaBeans
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 26
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Dfinition de JavaBeans
Un JavaBean est une classe Java qui respecte quelques conventions
Avoir un constructeur sans argument
Utiliser le motif JavaBean property pour exposer les valeurs au client
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 27
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Ce quon a couvert
Dfinition de JavaBeans
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 28
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Lapplication Web
Les balises JSP
Fabien Brissonneau
Site : http://www.alphorm.com Consultant, concepteur et formateur
Blog : http://blog.alphorm.com Objets Logiciels
Formation Java Server Faces alphorm.com
Plan
Les balises JSP standards
La balise forEach
La balise if
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 29
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
La balise forEach
Permet litration
Sur une squence de nombres, avec un incrment
Sur un conteneur
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 30
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
La balise if
Le corps de la balise que si lattribut test est valu vrai
Ce quon a couvert
Les balises JSP standard
La balise forEach
La balise if
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 31
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Lapplication Web
Les balises
personnalises
Fabien Brissonneau
Site : http://www.alphorm.com Consultant, concepteur et formateur
Blog : http://blog.alphorm.com Objets Logiciels
Formation Java Server Faces alphorm.com
Plan
Cration dune balise personnalise
Dclaration de la balise
Utilisation de la balise
Balise vs JavaBean
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 32
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Redfinir doTag()
Dclaration de la balise
Dans un fichier .tld
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 33
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Utilisation de la balise
Dclarer lusage de la bibliothque de balise
Balise vs JavaBean
Les deux cherchent sparer le code Java de la prsentation
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 34
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Ce quon a couvert
Cration dune balise personnalise
Dclaration de la balise
Utilisation de la balise
Balise vs JavaBean
La technologie JSF
Une application JSF
Fabien Brissonneau
Site : http://www.alphorm.com Consultant, concepteur et formateur
Blog : http://blog.alphorm.com Objets Logiciels
Formation Java Server Faces alphorm.com
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 35
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Plan
Quest-ce quune application JSF ?
Le modle de rendu
Le modle de conversion
Le modle dvnement
Le modle de validation
Le modle de navigation
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 36
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 37
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
UIForm : un formulaire
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 38
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Le modle de rendu
Une classe de rendu spare des classes de composants :
Adapter le rendu un client ou un type de client
Changer lapparence des composants sur une page
Le modle de conversion
Un composant peut tre associ un objet ct serveur
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 39
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Le modle dvnements
Conforme au modle classique des JavaBeans
Le modle de validation
La validation est excute avant la mise jour des donnes
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 40
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Le modle de navigation
La navigation est implicite ou dfinie par lutilisateur
Ce quon a couvert
Quest-ce quune application JSF ?
Le modle de rendu
Le modle de conversion
Le modle dvnement
Le modle de validation
Le modle de navigation
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 41
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
La technologie JSF
La navigation
Fabien Brissonneau
Site : http://www.alphorm.com Consultant, concepteur et formateur
Blog : http://blog.alphorm.com Objets Logiciels
Formation Java Server Faces alphorm.com
Plan
La navigation implicite
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 42
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
La navigation implicite
La page xhtml contient le nom de la page cible
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 43
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Ce quon a couvert
La navigation implicite
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 44
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
La technologie JSF
Le cycle de vie
Fabien Brissonneau
Site : http://www.alphorm.com Consultant, concepteur et formateur
Blog : http://blog.alphorm.com Objets Logiciels
Formation Java Server Faces alphorm.com
Plan
Requte initiale ou postback
La classe FacesContext
Lattribut immediate
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 45
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
La classe FacesContext
Nom complet javax.faces.context.FacesContext
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 46
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Lattribut immediate
Cet attribut va forcer la validation, les vnements et les conversions
tre valus dans la phase Apply Request
Il faut la cohrence entre la valeur de cet attribut sur un champ dentre
et sur les actions correspondantes
Par exemple, si un bouton a cet attribut vrai, il est trait avant que les
donnes des champs ne soient mises jour
Ce quon a couvert
Requte initiale ou postback
La classe FacesContext
Lattribut immediate
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 47
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Les facelets
Une application
Facelets
Fabien Brissonneau
Site : http://www.alphorm.com Consultant, concepteur et formateur
Blog : http://blog.alphorm.com Objets Logiciels
Formation Java Server Faces alphorm.com
Plan
Les facelets
Exemple
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 48
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Les facelets
Langage dclaratif pour construire des vues JSF
Utilisation de xhtml
Support de bibliothques de balises (facelets, jsf, jstl)
Support de Expression Language (EL)
Modles pour les composants et les pages
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 49
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Exemple dapplication
Crer les beans manags
Dfinir la navigation
Configurer lapplication
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 50
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 51
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Configurer lapplication
Configurer le servlet dans web.xml
Configuration de faces-config.xml
Divers
Une page template est un modle rcurrent dans lapplication
Dfini avec ui:insert et utilis avec ui:define
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 52
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Ce quon a couvert
Les facelets
Exemple
Les facelets
Construire une
application Facelets
Fabien Brissonneau
Site : http://www.alphorm.com Consultant, concepteur et formateur
Blog : http://blog.alphorm.com Objets Logiciels
Formation Java Server Faces alphorm.com
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 53
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Plan
Prparer un template
Prparer un template
Grce la balise ui:insert
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 54
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 55
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Utiliser ce composite
Rfrencer le fichier sauver dans un rpertoire
Ce quon a couvert
Prparer un template
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 56
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Les facelets
Les balises HTML5
Fabien Brissonneau
Site : http://www.alphorm.com Consultant, concepteur et formateur
Blog : http://blog.alphorm.com Objets Logiciels
Formation Java Server Faces alphorm.com
Plan
Les lments pass-through
Exemples
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 57
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 58
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Exemples
Balise Identifiant Facelets
a jsf:action h:commandlink
body h:body
input type=button h:commandButton
input type=checkbox h:selectBooleanCheckBox
input type=date h:inputText
input type=password h:inputSecret
link h:outputStyleSheet
Ce quon a couvert
Les lments pass-through
Exemples
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 59
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Expression Language
La syntaxe de EL
Fabien Brissonneau
Site : http://www.alphorm.com Consultant, concepteur et formateur
Blog : http://blog.alphorm.com Objets Logiciels
Formation Java Server Faces alphorm.com
Plan
Vue gnrale
Evaluation immdiate
Evaluation diffre
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 60
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Vue gnrale
Permet la communication entre la couche Web et les beans manags
Ce que permet EL
Expressions simples pour accder aux donnes des beans
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 61
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Evaluation immdiate
Lexpression est value ds que la page est rendue
Pas forcment trs pratique, tant donn le cycle de vie des pages
Evaluation diffre
Lexpression utilise la syntaxe #{}
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 62
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Ce quon a couvert
Vue gnrale
Evaluation immdiate
Evaluation diffre
Expression Language
Les expressions de
valeurs
Fabien Brissonneau
Site : http://www.alphorm.com Consultant, concepteur et formateur
Blog : http://blog.alphorm.com Objets Logiciels
Formation Java Server Faces alphorm.com
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 63
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Plan
Expression gnrale
Rfrencement dobjets
Rfrencement de proprits
Les littraux
Expression gnrale
Les expressions de valeurs peuvent tre r-value ou l-value
Utilises en lecture ou en criture
Avec JSF :
Requte initiale : lit lexpression
Postback : ventuellement positionnement de la valeur
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 64
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Rfrencement dobjets
Lexpression dmarre sur un objet de haut-niveau :
Des paramtres, variables EL, beans manags, objets implicites, classes
Rfrencement de proprits
Utiliser la notation de slection . ou [ ]
Par exemple :
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 65
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Les littraux
Quelques littraux sont prdfinis
Boolens : true, false,
Entiers : comme Java
Flottants : comme Java
Texte : entre double ou simple quotes
Null : null
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 66
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Ce quon a couvert
Expression gnrale
Rfrencement dobjets
Rfrencement de proprits
Les littraux
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 67
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Expression Language
Les expressions de
mthodes
Fabien Brissonneau
Site : http://www.alphorm.com Consultant, concepteur et formateur
Blog : http://blog.alphorm.com Objets Logiciels
Formation Java Server Faces alphorm.com
Plan
Syntaxe gnrale
Lambda expressions
Exemples doprateurs
Mots rservs
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 68
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Syntaxe gnrale
Les expressions de mthodes sont diffres
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 69
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Exemples doprateurs
Il est possible dappliquer des oprateurs
Arithmtiques
Logiques
Relationels
Conditionel
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 70
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Mots rservs
Certains mots rservs ne peuvent pas tre utiliss en EL :
And, or, not, eq, ne
Ce quon a couvert
Syntaxe gnrale
Lambda expressions
Exemples doprateurs
Mots rservs
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 71
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Fabien Brissonneau
Site : http://www.alphorm.com Consultant, concepteur et formateur
Blog : http://blog.alphorm.com Objets Logiciels
Formation Java Server Faces alphorm.com
Plan
Vue gnrale
Les formulaires
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 72
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Vue gnrale
Une page JSF typique contient
Les espaces de nommage dclarant les bibliothques utilises
Les dfinitions de entte et corps de page
Un formulaire
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 73
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 74
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Les formulaires
Le formulaire contient les composants qui prsentent les donnes ou
qui servent entrer les donnes
Utiliser la balise <h:form>
Plusieurs formulaires sont possibles dans une page, mais seules les
donnes lies ce formulaire seront envoyes lors du postback de
soumission
Le formulaire ne propose aucune disposition des lments dans la page
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 75
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Ce quon a couvert
Vue gnrale
Les formulaires
Fabien Brissonneau
Site : http://www.alphorm.com Consultant, concepteur et formateur
Blog : http://blog.alphorm.com Objets Logiciels
Formation Java Server Faces alphorm.com
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 76
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Plan
Les diffrents types de textes
Utiliser outputFormat
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 77
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 78
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 79
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Utiliser outputFormat
Formater un texte
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 80
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Ce quon a couvert
Les diffrents types de textes
Utiliser outputFormat
Fabien Brissonneau
Site : http://www.alphorm.com Consultant, concepteur et formateur
Blog : http://blog.alphorm.com Objets Logiciels
Formation Java Server Faces alphorm.com
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 81
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Plan
Rles des composants de commande
Rendre un bouton
Rendre un lien
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 82
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Rendre un bouton
Utiliser h:commandButton
Rendre un lien
Utiliser h:commandLink
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 83
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Ce quon a couvert
Rles des composants de commande
Rendre un bouton
Rendre un lien
Fabien Brissonneau
Site : http://www.alphorm.com Consultant, concepteur et formateur
Blog : http://blog.alphorm.com Objets Logiciels
Formation Java Server Faces alphorm.com
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 84
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Plan
Les composants de slection
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 85
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 86
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Ce quon a couvert
Les composants de slection
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 87
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Plan
Objectifs de ces composants
Sources de donnes
Attributs optionnels
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 88
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Sources de donnes
La source de donnes peut tre
Une collection de beans
Un bean simplement
Un objet javax.faces.model.DataModel
Un objet java.sql.ResultSet
Un objet javax.servlet. Sql.Result
Un objet javax.sql.RowSet
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 89
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Attributs optionnels
Dans h:dataTable , rows et first spcifient le nombre et la premire ligne
Ce quon a couvert
Objectifs de ces composants
Sources de donnes
Attributs optionnels
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 90
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Fabien Brissonneau
Site : http://www.alphorm.com Consultant, concepteur et formateur
Blog : http://blog.alphorm.com Objets Logiciels
Formation Java Server Faces alphorm.com
Plan
Afficher une image
Afficher un message
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 91
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Afficher un message
Utiliss lors des checs de validation ou formatage
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 92
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Ce quon a couvert
Afficher une image
Afficher un message
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 93
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Fabien Brissonneau
Site : http://www.alphorm.com Consultant, concepteur et formateur
Blog : http://blog.alphorm.com Objets Logiciels
Formation Java Server Faces alphorm.com
Plan
Grouper en table
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 94
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Grouper en table
Utiliser h:panelGrid, rendu comme un TABLE
Spcifier
le nombre de colonnes, titre, etc
Des styles css pour les diffrentes parties de la table
Peut contenir entte et bas de page
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 95
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Ce quon a couvert
Grouper en table
Converters etc
Les convertisseurs
standards
Fabien Brissonneau
Site : http://www.alphorm.com Consultant, concepteur et formateur
Blog : http://blog.alphorm.com Objets Logiciels
Formation Java Server Faces alphorm.com
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 96
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Plan
Rles et usage des convertisseurs
DateTimeConverter
NumberConverter
Et vis versa
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 97
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
DateTimeConverter
Cible le type java.util.Date
NumberConverter
Utiliser le composant maxFractionDigits,
h:convertNumber maxIntegerDigits, min-
binding type
currencyCode
for
groupingUsed
integerOnly
locale
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 98
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Ce quon a couvert
Rles et usage des convertisseurs
DateTimeConverter
NumberConverter
Converters etc
Les listeners
Fabien Brissonneau
Site : http://www.alphorm.com Consultant, concepteur et formateur
Blog : http://blog.alphorm.com Objets Logiciels
Formation Java Server Faces alphorm.com
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 99
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Plan
Rle et intrt des listeners
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 100
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 101
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Ce quon a couvert
Rle et intrt des listeners
Converters etc
Les validateurs
Fabien Brissonneau
Site : http://www.alphorm.com Consultant, concepteur et formateur
Blog : http://blog.alphorm.com Objets Logiciels
Formation Java Server Faces alphorm.com
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 102
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Plan
Rle et objectifs des validateurs
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 103
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Ne peut tre utiliser que sur les composants qui permettent ldition de
valeurs
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 104
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Expression rgulire
Une expression rgulire peut permettre de vrifier
Mots de passe, email, tlphones,
Ce quon a couvert
Rle et objectifs des validateurs
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 105
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Fabien Brissonneau
Site : http://www.alphorm.com Consultant, concepteur et formateur
Blog : http://blog.alphorm.com Objets Logiciels
Formation Java Server Faces alphorm.com
Plan
Les liaisons entre composant et bean
Exemple de liaisons
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 106
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
La liaison de value
La valeur est porte par le composant
La page a tout contrle sur le composant
Il ny a pas de dpendance de la page vers Java
Les conversions interviennent de manire transparentes
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 107
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
La liaison de binding
Les attributs du composant peuvent tre modifis par le bean
Accs via la programmation applicative
Le bean instancie le composant
Exemples de laisons
Les liaisons par valeur peuvent tre plus complexes quun accs une
proprit de bean
Expression boolenne
Une proprit venant dun paramtre
Une proprit de bean
Une valeur dans un tableau
Une valeur dans une collection
Une proprit dun objet dans une collection
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 108
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Ce quon a couvert
Les liaisons entre composant et bean
Exemple de liaisons
Fabien Brissonneau
Site : http://www.alphorm.com Consultant, concepteur et formateur
Blog : http://blog.alphorm.com Objets Logiciels
Formation Java Server Faces alphorm.com
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 109
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Plan
Mise en uvre
Mise en oeuvre
Postionner lattribut value
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 110
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Ce quon a couvert
Mise en uvre
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 111
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Fabien Brissonneau
Site : http://www.alphorm.com Consultant, concepteur et formateur
Blog : http://blog.alphorm.com Objets Logiciels
Formation Java Server Faces alphorm.com
Plan
Intrt
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 112
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Intrt
Lier les instances supposent que le bean cre le composant
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 113
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Ce quon a couvert
Intrt
Ajax et JSF
Gnralits
Fabien Brissonneau
Site : http://www.alphorm.com Consultant, concepteur et formateur
Blog : http://blog.alphorm.com Objets Logiciels
Formation Java Server Faces alphorm.com
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 114
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Plan
Vue densemble
Vue densemble
Les interactions peuvent tre asynchrones
Avantages attendus
Validation des formulaires en temps rel
Fonctionnalits nouvelles
Mise jour partielle
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 115
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 116
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Ce quon a couvert
Vue densemble
Ajax et JSF
Envoyer une requte
Ajax
Fabien Brissonneau
Site : http://www.alphorm.com Consultant, concepteur et formateur
Blog : http://blog.alphorm.com Objets Logiciels
Formation Java Server Faces alphorm.com
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 117
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Plan
Utiliser lattribut event
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 118
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 119
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Ce quon a couvert
Utiliser lattribut event
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 120
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Ajax et JSF
Grer les erreurs
Fabien Brissonneau
Site : http://www.alphorm.com Consultant, concepteur et formateur
Blog : http://blog.alphorm.com Objets Logiciels
Formation Java Server Faces alphorm.com
Plan
Suivre les vnements
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 121
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 122
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Ce quon a couvert
Suivre les vnements
Ajax et JSF
Recevoir une rponse
Fabien Brissonneau
Site : http://www.alphorm.com Consultant, concepteur et formateur
Blog : http://blog.alphorm.com Objets Logiciels
Formation Java Server Faces alphorm.com
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 123
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Plan
Recevoir la rponse
Recevoir la rponse
Utiliser lattribut render
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 124
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 125
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Ce quon a couvert
Recevoir la rponse
Configurer lapplication
Annotations sur les
beans manags
Fabien Brissonneau
Site : http://www.alphorm.com Consultant, concepteur et formateur
Blog : http://blog.alphorm.com Objets Logiciels
Formation Java Server Faces alphorm.com
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 126
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Plan
Les annotations de porte
La cration en avance
Session
Accessible travers toutes les requtes HTTP (une connexion )
Flow
Accessible travers un flux donn
Request
Accessible pour une requte
Dependent
Indique que le bean dpend de la visibilit dun autre bean
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 127
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
La cration en avance
Les beans sont normalement crs la demande
Ce quon a couvert
Les annotations de porte
La cration en avance
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 128
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Configurer lapplication
Configurer les beans
avec XML
Fabien Brissonneau
Site : http://www.alphorm.com Consultant, concepteur et formateur
Blog : http://blog.alphorm.com Objets Logiciels
Formation Java Server Faces alphorm.com
Plan
Le fichier de configuration
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 129
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Le fichier de configuration
Dans faces-config.xml
La balise <managed-bean>
Dcrire
La classe
Le nom
La porte
Des valeurs initiales pour les proprits
Intrts
Paramtrage indpendant du code
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 130
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Ce quon a couvert
Le fichier de configuration
Configurer lapplication
Prise en compte de la
langue
Fabien Brissonneau
Site : http://www.alphorm.com Consultant, concepteur et formateur
Blog : http://blog.alphorm.com Objets Logiciels
Formation Java Server Faces alphorm.com
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 131
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Plan
Construction des ressources langage
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 132
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 133
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Ce quon a couvert
Construction des ressources langage
Configurer lapplication
Faces flows
Fabien Brissonneau
Site : http://www.alphorm.com Consultant, concepteur et formateur
Blog : http://blog.alphorm.com Objets Logiciels
Formation Java Server Faces alphorm.com
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 134
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Plan
Dfinition
Mise en uvre
Configuration
Dfinition
Une porte spcifique des variables : flowScope
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 135
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Y placer
Un fichier de config <nom_du_flux>.xml (vide)
Un fichier dentre <nom_du_flux>.xhtml
Autant de fichiers xhtml que ncessaires
Un retour
<nom_du_flux>-return.xml
Configuration
Le flux peut tre configur
Par fichier
Dans le rpertoire du flux
- Nom du flux, son point de retour
Par annotations
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 136
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Ce quon a couvert
Dfinition
Mise en uvre
Configuration
Configurer lapplication
La scurit
Fabien Brissonneau
Site : http://www.alphorm.com Consultant, concepteur et formateur
Blog : http://blog.alphorm.com Objets Logiciels
Formation Java Server Faces alphorm.com
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 137
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Plan
Les mthodes dauthentification
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 138
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Dans web.xml
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 139
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Ce quon a couvert
Les mthodes dauthentification
Conclusion
Fabien Brissonneau
Site : http://www.alphorm.com Consultant, concepteur et formateur
Blog : http://blog.alphorm.com Objets Logiciels
Formation Java Server Faces alphorm.com
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 140
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Nous avons vu
Chapitre 1 : Lapplication Web
Et la suite ?
La formation JEE persistence
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 141
Alphorm.com-Support de la 25/01/2017
Formation Java Server Faces
Conclusion
Merci et bientt !
TOUTE UTILISATION EN
DEHORS DE ALPHORM EST
INTERDITE 142