Outils pour utilisateurs

Outils du site


helloworld:web:java:taglib:jsp

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
Prochaine révision
Révision précédente
helloworld:web:java:taglib:jsp [2015/08/13 22:35] – Nettoyage roothelloworld:web:java:taglib:jsp [2020/05/10 23:57] (Version actuelle) – Suppression de la taille par défaut pour les images root
Ligne 1: Ligne 1:
-Nécessite un projet de type [[eclipse:howto:dwp|Dynamic Web Project]].+Nécessite un projet de type [[ide:eclipse:projet|Dynamic Web Project]].
  
 +=====Cas général=====
 <file xml tagperso.tld> <file xml tagperso.tld>
 <?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
Ligne 24: Ligne 25:
 </javaee:taglib> </javaee:taglib>
 </file> </file>
-<note>''rtexprvalue'' permet l'utilisation des EL dans les attributs.</note>+ 
 +<WRAP center round info 60%> 
 +''rtexprvalue'' permet l'utilisation des EL dans les attributs. 
 +</WRAP> 
 <file java TagPerso.java> <file java TagPerso.java>
 package com.llgc; package com.llgc;
Ligne 119: Ligne 124:
 Le corps du message : Corps. Le corps du message : Corps.
 </code> </code>
 +
 +=====Ajout d'un validateur des attributs=====
 +La méthode ''isValid'' est exécutée avant la classe générant le code ''HTML'' et génère une exception (et donc fait échouer le chargement de la page) si elle renvoie ''false''.
 +
 +<file java TagPersoExtra.java>
 +package com.llgc;
 +
 +import java.util.Enumeration;
 +
 +import javax.servlet.jsp.tagext.TagData;
 +import javax.servlet.jsp.tagext.TagExtraInfo;
 +
 +public class TagPersoExtra extends TagExtraInfo
 +{
 +  @Override
 +  public boolean isValid (TagData tagData)
 +  {
 +    Enumeration <String> attr = tagData.getAttributes ();
 +    System.out.println ("B");
 +    while (attr.hasMoreElements ())
 +    {
 +      String it = attr.nextElement ();
 +      if (it.equals ("attribute1") && tagData.getAttributeString (it) == null)
 +      {
 +        return false;
 +      }
 +      System.out.println (it + " : " + tagData.getAttributeString (it));
 +    }
 +    return super.isValid (tagData);
 +  }
 +}
 +</file>
 +
 +<file xml tagperso.tld>
 +<?xml version="1.0" encoding="UTF-8"?>
 +<javaee:taglib version="2.1" xmlns:javaee="http://java.sun.com/xml/ns/javaee"
 +  xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 +  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd ">
 +  <javaee:tlib-version>2.1</javaee:tlib-version>
 +  <javaee:short-name>tagperso</javaee:short-name>
 +  <javaee:tag>
 +    <javaee:name>nomtag</javaee:name>
 +    <javaee:tag-class>com.llgc.TagPerso</javaee:tag-class>
 +    <javaee:tei-class>com.llgc.TagPersoExtra</javaee:tei-class>
 +    …
 +  </javaee:tag>
 +</javaee:taglib>
 +</file>
 +
 +<WRAP center round important 60%>
 +Dans mon cas, pour que les modifications dans TagPersoExtra soient prises en compte, à chaque fois, il fallait que je réenregistre la page ''.JSP'', comme si le cache ne détectait pas la dépendance et n'actualisait pas la compilation de TagPersoExtra.
 +</WRAP>
 +
 +Rendu (si ''isValid'' renvoie faux) :
 +{{:helloworld:web:java:taglib:jsp:rendu_ex2_fail.png|Échec de la fonction ''isValid''}}
helloworld/web/java/taglib/jsp.1439498145.txt.gz · Dernière modification : 2015/08/13 22:35 de root