Formation Java Server Faces 1 Participant : Mr Frédéric MULLER - Formation JEE/JSF – Groupement...

89
Formation Java Server Faces 1 Participant : Mr Frédéric MULLER www.objis.com - Formation JEE/JSF – Groupement Informatique

Transcript of Formation Java Server Faces 1 Participant : Mr Frédéric MULLER - Formation JEE/JSF – Groupement...

Page 1: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

Formation Java Server Faces

1

Participant : Mr Frédéric MULLER

www.objis.com - Formation JEE/JSF – Groupement Informatique

Page 2: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

SOMMAIRERappels J2EE p 3Positionnement JSF et architecture p 9Cycle de vie JSF p 21Packages clés et composants JSF natifs p 23Composants supplémentaires RichFaces p 28Composants supplémentaires : IceFaces p 32Exemple cinématique application JSF p 39 Problématique JSP / JSF et réponse Facelet p 44Exemple mise en oeuvre Facelet / IceFaces p 53Listeners personalisés p 62RichFaces configuration p 69Méthode création composant personnalisé p 80

2www.objis.com - Formation JSF

Page 3: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

RAPPELS J2EE

Architecture multicouche

Architecture J2EE

Livrables J2EE

Services J2EE

Roles J2EE

Concepts techniques clés

3www.objis.com - Formation JSF

Page 4: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

Rappel J2EE :Architecture multicouche

4

Page 5: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

Rappel J2EE :Architecture J2EE

5

Page 6: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

Livraisons J2EE

6

Page 7: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

Services J2EE

JNDI : Java Naming Directory Interface

JCA : Java Connector Architecture

JTA : Java Transaction API

JPA : Java Persistence API

JMS : Java Message Service

JAAS : Java Authentication & Authorisation Service

JAX-WS : Java API for XML Web Services

JAXB : Java API for XML Binding7

Page 8: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Concepts techniques clés

Injection de dépendances

Programmation Orientée Aspects / Interception

Annotations

Mapping Objet / Relationnel

Sécurité

Transaction

8www.objis.com - Formation JSF

Page 9: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Positionnement et architecture JSF Contexte création JSF

Versions et Implémentations

JSF dans J2EE

JSF et le pattern MVC

Cycle de vie requête JSF

Packages et composants JSF

Composants additionnels : RichFaces / IceFaces9www.objis.com - Formation JSF

Page 10: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Contexte développement d’applications Java/J2ee en 2001

JSP + ServletsForce: bien maîtrisé développeursFaiblesse: maintenance !

StrutsForce: Framework web MVC2Faiblesse: création interfaceFaiblesse: peu d’outils RAD

Swing : Force: Composants graphiquesForce: Outils RADFaiblesse: pas d’équivalent web !

Besoin framework web MVC RAD10www.objis.com - Formation JSF

Page 11: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Naissance de JSF

Besoin framework et outils web RAD‘Composants’ visuelsGestion état écran Gestion évènements client MultilingueValidation entrée utilisateurAffichage adapté (pda,portable…)AccessibilitéNavigation entre page

Acteurs : IBM, SUN, BEA, ORACLE Mars 2004 : spécifications JSF 1.0 Mai 2004 : spécifications JSF 1.1

11www.objis.com - Formation JSF

Craig Mac Clanahan

Ed Burns

Amy Fowler

Page 12: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Versions JSF et API J2EE

JSF 1.1 (mai 2004) JSR 127 : http://jcp.org/en/jsr/detail?id=127 servlet 2.3 + JSP 1.2 + Java 1.3

JSF 1.2 (août 2006)JSR 252 : http://jcp.org/en/jsr/detail?id=252Servlet 2.5 + JSP 2.1 + Java 5

JSF 2.0 (juillet 2009)JSR 314 : http://jcp.org/en/jsr/detail?id=314Servlet 2.5 + JSP 2.1 + Java 5+Profil web JEE6

12www.objis.com - Formation JSF

Page 13: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Implémentations de JSF

Mojarra : implémentation de référence (SUN) Librairies : jsf-api.jar, jsf-impl.jar Composants natifs : core, html

MyFaces : implémentation ApacheLibrairies : myfaces-api, myfaces-implComposants : TomaHawk, Tobago, Trinidad

Nombreuses autres Détail et comparaison : www.jsfmatrix.net

13www.objis.com - Formation JSF

Page 14: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Architecture & positionnement JSF

14www.objis.com - Formation JSF

Page 15: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Architecture & positionnement JSF

15www.objis.com - Formation JSF

Page 16: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

JSF dans application J2EE

16www.objis.com - Formation JSF

Page 17: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

JSF et le modèle MVC

17www.objis.com - Formation JSF

Page 18: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Exemple

18www.objis.com - Formation JSF

Page 19: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Caractéristiques JSF

Développement évènementiel orienté Composant

Simplifie accès et gestion données métiers Automatise & simplifie gestion état écran entre

plusieurs requêtes Mise en oeuvre de patterns connus Masque bas niveau (HttpServletRequest/Response) Meilleure maintenance

19www.objis.com - Formation JSF

Page 20: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Modèle évènementiel JSF

Evènements liés aux ‘actions’ utilisateurs Appui boutton, clic sur lien hypertexte…. Tout composant implémentant ‘ActionSource’

Evènements liés à MAJ interface par l’utilisateur Modification données champ texte, comboTout composant implémentant ‘EditableValueHolder’

Evènements liés aux données du modèle métier Les 'listeners' traitent les évènements

20www.objis.com - Formation JSF

Page 21: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Cycle de requêtes JSF

21www.objis.com - Formation JSF

Page 22: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Cycle de vie requête JSF : 6 étapes clés ordonnées

1) Restauration vue (Arbre composants ecran)

2) Appliquer paramètres requête

3) Validation (& conversion) entrées utilisateur

4) Mise à jour des objets Modèle (backing beans)

5) Exécution Appli (ActionEvent, ValueChangeEvent…)

6) Rendu de la réponse (Render)

22www.objis.com - Formation JSF

Page 23: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Packages / Javadoc JSF

23www.objis.com - Formation JSF

JSF 1.1

JSF 1.2

JSF 2.0

Page 24: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Composants JSF

24www.objis.com - Formation JSF

Comportement

Composant

Page 25: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Composants JSF rendu HTML disponible avec Mojarra

25www.objis.com - Formation JSF

25 composants : pas assez de choix !

Page 26: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Exemples Composants :Héritage et comportement spécifique

26www.objis.com - Formation JSF

Page 27: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Packages / Javadoc JSF :Le contexte FacesContext

www.objis.com - Formation JSF

JSF 1.2

Page 28: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Composants JSF supplémentaires

RichFaces (Jboss) : www.jboss.org/richfaces Fusion projets Jboss 'RichFaces' et 'Ajax4jsf'

• Le développeur choisit les zones de la page à traiter coté serveur + zones à mettre à jour • + de 100 composants UI avec support Ajax testés avec différents navigateurs

Chaque composant : + de 30 attributsTags (a4j: et rich:)Skins (DEFAULT, blueSky, plain, laguna...) CDK (Components Development Kit)

IceFaces (www.icefaces.org) Composants MyFaces (http://myfaces.apache.org)

28www.objis.com - Formation JSF

Page 29: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Rappels Ajax

29www.objis.com - Formation JSF

Page 30: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

JSF et Ajax avec RichFaces

Ajax4jsf : né de la volonté de créer applications riches / Ajax avec JSF

Ajax4jsf : filtre qui ajoute des fonctions javascript ainsi que les dépendances de l’objet XmlHttpRequest aux composants JSF

Suite à requete HTTP, le moteur Ajax transforme la requête et l’envoi au filtre Ajax4jsf

Le filtre Ajax4jsf convertit les données au format XML et transfère la requête à la servlet FacesServlet, pour réaliser cycle 6 étapes JSF

30www.objis.com - Formation JSF

Page 31: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

JSF et Ajax avec RichFaces

31www.objis.com - Formation JSF

Page 32: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Composants JSF supplémentaires

IceFaces (IceSoft) : www.icefaces.org Leader historique sur JSF + Ajax/Web2Technologies Skinning, Multimedia, AJAX Push Intégration avec

• JSF 1.x / JSF 1.2 / Facelet• Spring Web Flow• Jboss Seam • MyFaces Tomahawk• Portails : Liferay, Jboss Portal, WebLo. Portal• IDE : Eclipse, MyEclipse, Netbeans

Communauté : 100.000 développeurs+

32www.objis.com - Formation JSF

Page 33: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

JSF et Ajax avec IceFaces

33www.objis.com - Formation JSF

Page 34: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Librairies Icefaces

Dépendences icefaces 181

34www.objis.com - Formation JSF

Page 35: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

IceFaces : plugin Eclipse

Intégration du plugin dans Eclipse• Manuelle si version plugin < 3.6.2

– Exemple : eclipse 3.4 + Icefaces 1.8.1• Sinon Update site : icefaces.org/eclipse-updates

– Exemple : dès Eclipse 3.5

Valeur ajoutée du plugin pour développeur :• Création projets Web JSF ICeFaces • Création projets Web JSF IceFaces + Facelet• Complétion de code• Gestion visuelle composants graphiques

35www.objis.com - Formation JSF

Page 36: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

IceFaces : Plugin Eclipse

36

Plugin IceFaces (dézipper archive + install eclipse 'local')

Plugin JbossTools pour intégration Jboss (dézipper le zip dans répertoire 'eclipse')

Plugin m2eclipse (Maven)

Page 37: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

IceFaces : industrialiser développements

AppFuse : squelettes projets (archetypes maven)• www.appfuse.org • Initié en 2002 par Mark Raible• Squelettes appli. Struts/Jsf + hibernate/spring...• Aucun squelette avec Icefaces en frontal !

Edoras : • www.edorasframework.org• Initié par MIMACOM, qui fournit support

IceFaces en Europe (mimacom.ch)

IceFusion = AppFuse pour IceFaces• icefusion.googlecode.com 37

Page 38: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Développement IceFaces

38www.objis.com - Formation JSF

Page 39: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Démo JSF : Cinématique application

39www.objis.com - Formation JSF

index.jsp Main.jsp

Confirm.jsp

Register.jsp Done.jsp

Page 40: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Configuration JSF : fichier web.xml

40www.objis.com - Formation JSF

1

2

Page 41: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Enchaînement accueilécran JSF

41www.objis.com - Formation JSF

1

2

3

4

5

0

Page 42: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Configuration JSF : faces-config.xml

42www.objis.com - Formation JSF

1 2

3

Page 43: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Intégration JSP / JSF

Objectifs différents JSP : html + java / traitement ‘de haut en bas’ JSF : composants / traitement évènementiel

Cycle de vie différent JSP Java html JSF : cycle de requête précis (6 étapes)

Etapes gestion composant JSF création + gestion entrée + rendu

Etapes composant JSF dans JSP En parrallèle : création & rendu

Ajout de conenu dans la page par JSF & JSP En parallèle : création & rendu !

43www.objis.com - Formation JSF

Page 44: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Intégration JSP / JSF :Exemple de problème

44www.objis.com - Formation JSF

Page 45: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Intégration JSP / JSF :Comprendre la technologie Facelet

45www.objis.com - Formation JSF

Technologie de Vue adaptée à JSF ViewHandler

S’insère bien dans le cycle requête JSF http://facelets.dev.java.net

Page 46: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Intégration JSP / JSF :Comprendre la technologie Facelet

46www.objis.com - Formation JSF

Page 47: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Facelet : Configuration

47www.objis.com - Formation JSF

1

3

2

Web.xml

Faces-config.xml

Page 48: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Facelet : template.xhtml

48www.objis.com - Formation JSF

Page 49: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Facelet : Exemple ecran 1 (guess.xhtml)

49www.objis.com - Formation JSF

1

2

4

3

Page 50: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Facelet : rendu ecran 1 (guess.xhtml)

50www.objis.com - Formation JSF

3

4

Page 51: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Facelet : Exemple ecran 2 (response.xhtml)

51www.objis.com - Formation JSF

1

2

4

3

Permet collaboration développeur / webdesigner

Page 52: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Facelet : rendu ecran 2 (response.xhtml)

52www.objis.com - Formation JSF

Page 53: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

Démo Facelet avec IceFaces :Template v1 (merci Eclipse !)

53

Page 54: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

Démo Facelet avec IceFaces :Template v2

54

Page 55: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

Démo Facelet avec IceFaces :Template v3

55

Page 56: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

Démo Facelet avec IceFaces :Template v4

56

Page 57: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

Démo Facelet avec IceFaces :Page v0

57

Page 58: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

Démo Facelet avec IceFaces :Page v1

58

Page 59: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

Démo Facelet avec IceFaces :Page v1 rendu

59

Page 60: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

Démo Facelet avec IceFaces :Page v2

60

Page 61: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

Démo Facelet avec IceFaces :Page v2 rendu

61

Page 62: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Création listener personnalisé

62www.objis.com - Formation JSF

Pour écouter et traiter 3 types d’évènements Type 1 : actions utilisateur

Action event déclenché par bouton ou lienType 2 : changement de valeur champ

inputTextType 3 : phases JSF

Une des 6 phases traitement requête.

Accès par programmation à l’évènement (ActionEvent) ou au contexte JSF (FacesContext)

Page 63: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Comprendre un ActionEvent

63www.objis.com - Formation JSF

Page 64: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Création listener type 1 : action utilisateur

64www.objis.com - Formation JSF

1

2

Page 65: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Création listener type 2 : changement valeur champ

65www.objis.com - Formation JSF

1

2

Page 66: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Création listener type 3 : phases JSF

66www.objis.com - Formation JSF

1

2

Page 67: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Création listener type 3 : exemple logs phases JSF

67www.objis.com - Formation JSF

Page 68: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

JSF et Ajax

Ajax4jsf gère arbre de composants tout au long de la requête / réponse Ajax.

68www.objis.com - Formation JSF

Page 69: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

RichFaces

Bibliothèque composants graphiques JSF Basé sur Ajax4jsf (+ ajout skins + composants) <a4j:> et <rich:> + de 100 composants visuels demos : jboss.org/richfaces/demos.html

JSF 1.2 / RichFace 3.x RI Mojarra MyFaces 1.2

JSF 2 / RichFaces 4

69www.objis.com - Formation JSF

Page 70: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Composants a4j : <a4j:support>

Permet d’ajouter le support d’ajax aux composants JSF de base

Attribut ‘event’ : évènement javascript qui lance la requête ajax

Attribut ‘reRender’ : contient les ids des composants à mettre à jour lors du retour de la réponse

Attribut ‘actionListener’ : binding de la méthode qui prend un ActionEvent en paramètre et retourne un type void.

Attribut ‘action’ : binding de la méthode qui invoque l’action de l’application

70www.objis.com - Formation JSF

Page 71: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Attributs commun A4J / RichFaces

reRender ajaxSingle : booléen pour limiter les phases 2,3,4 seulement au

composant qui envoie la requête Immediate : comme en jsf, pour éviter phase

validation/conversion bypassUpdates : permet d’éviter phases MAJ modèle +

invocation application pour passer directement à phase rendu réponse.

onComplete : code à exécuter coté client à la fin de la requête limitTolist : si valeur est true, la mise à jour des composants coté

clients se limite à la liste dans l’attribut reRender timeOut : Max durée requête ajax Data : permet de récupérer du serveur une donnée durant la

requête ajax. Ex : propriété d’un bean avec EL (sérialisée via JSON)

71www.objis.com - Formation JSF

Page 72: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Intégration JSF / RichFaces

72www.objis.com - Formation JSF

1

2

3

Optionnel : intégration avec Facelets

Filtre RichFaces

Page 73: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Intégration JSF / RichFaces

73www.objis.com - Formation JSF

Page 74: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Intégration Facelet / RichFaces

74www.objis.com - Formation JSF

Page 75: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Intégration Facelet / RichFaces

75www.objis.com - Formation JSF

Page 76: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Modification Skins

76www.objis.com - Formation JSF

Skins par défaut dans META-INF/skins de l’archive RichFaces-impl-xxx.jar blueSky, Laguna, classic, glass-x,…

Pour personnaliser skin, désarchiver richfaces-impl-xxx.jarSur un fichier .properties, faire modif css désiréesArchiver à nouveau le jar et mettre ds projet

Web.xml

Page 77: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Concepts clés RichFaces

77www.objis.com - Formation JSF

Concept N°1 : envoi d'une requête Ajax– <a4j:commandLink>,<a4j:commandButton>– <a4j:support>– <a4j:poll>– Attribut limitToList

Concept N°2 : mise à jour partielle de la page– Attribut reRender– <a4j:outputPanel>

Concept N°3 : zones à traiter coté serveur– <a4j:region>– Attribut AjaxSingle– Attribut process

Page 78: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Composants clés RichFaces

78

Composants d'entrée– <rich:inplaceInput>, <rich:inplaceSelect>

– <rich:suggestionBox>, <rich:comboBox>,...

Composants de sortie– <rich:panel>,<rich:simpleTogglepanel>

– <rich:tabPanel>,<rich:modalPanel>,<rich:PanelBar> Composants d'itération de données

– <rich:dataTable>, <rich:dataList>,<rich:dataGrid>

– <rich:dataScroller> (Pagination)

Composants de sélection– <rich:pickList>, <rich:orderingList>

Composants de Menu– <rich:dropDownMenu>, <rich:contextMenu>

Données et arbres scrollables– <rich:scrollableDataTable>, <rich:tree>

Page 79: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Concept N°1 : envoi requête Ajax

79www.objis.com - Formation JSF

Page 80: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Création composant personnalisé

80www.objis.com - Formation JSF

1) Créer classe hérite de javax.faces.component.UIComponentBaseRedéfinir ma méthode encodeBegin(FaceContext context)Si attribut, alors redéfinir encodeEnd()

2) Enregistrer la classe dans faces-config.xml balise <component>

3) Créer un Tag spécifique (classe héritant de UIComponentTag)Ex : sf:sellerHello

4) Créer le descripteur (TLD) du Tag

Exemple : http://www.theserverside.com/news/1364786/Building-Custom-JSF-UI-Components

Page 81: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Composant personnalisé : Comprendre son environnement

81www.objis.com - Formation JSF

Page 82: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Composant personnalisé : Comprendre les sollicitations

82www.objis.com - Formation JSF

Méthodes à gérer :

ProcessDecodesProcessValidatorsProcessUpdatesProcessApplication

RenderResponse

Lnacées par UIViewRootà differentes phases du cycle de vie

Page 83: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Composant personnalisé : Comprendre UIViewRoot

83www.objis.com - Formation JSF

Page 84: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Impact à chaque phase

84www.objis.com - Formation JSF

Phase 1 (Restauration de la vue)Gestion de l'état (coté client ou serveur) : sauver / restaurer (optionnel) Implémenter javax.faces.component.StateHolder

• Ex : saveState retourne tableau d'objets Sérialisables

• Ex : restoreState attend un tableau d'objets Sérialisables

Phase 2 (Traitement de la requête) 'Décoder' (exploiter en interne) les paramètres de requête

• Le faire dans composant OU déléguer à classe (Renderer) Impulsion par méthode processDecode du UIViewRoot (obligatoire) Implémeter méthode decode()Decode() travailler avec le Renderer

3) Créer un

Page 85: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Création composant personnalisé

85www.objis.com - Formation JSF

1) Créer classe hérite de javax.faces.component.UIComponentBaseRedéfinir ma méthode encodeBegin(FaceContext context)Si attribut, alors redéfinir encodeEnd()

2) Enregistrer la classe dans faces-config.xml balise <component>

3) Créer un Tag spécifique (classe héritant de UIComponentTag)Ex : sf:sellerHello

4) Créer le descripteur (TLD) du Tag

Exemple : http://www.theserverside.com/news/1364786/Building-Custom-JSF-UI-Components

Page 86: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Composant personnalisé : Rendu visuel (Render)

86www.objis.com - Formation JSF

Page 87: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Composant personnalisé : decode() dans composant

87www.objis.com - Formation JSF

Page 88: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Composant personnalisé : decode() dans Renderer perso

88www.objis.com - Formation JSF

Page 89: Formation Java Server Faces 1 Participant : Mr Frédéric MULLER  - Formation JEE/JSF – Groupement Informatique.

www.objis.com - INTEGRATION CONTINUEwww.objis.com - Formation SPRING

Composant personnalisé : encodeBegin()

89www.objis.com - Formation JSF