helloworld:web:java:taglib:jsp
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
helloworld:web:java:taglib:jsp [2015/08/13 19:12] – Ajout de l'exemple 2 root | helloworld: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]]. |
- | + | ||
- | =====JSP pur===== | + | |
+ | =====Cas général===== | ||
<file xml tagperso.tld> | <file xml tagperso.tld> | ||
<?xml version=" | <?xml version=" | ||
Ligne 26: | Ligne 25: | ||
</ | </ | ||
</ | </ | ||
- | <note>'' | + | |
+ | <WRAP center round info 60%> | ||
+ | '' | ||
+ | </WRAP> | ||
<file java TagPerso.java> | <file java TagPerso.java> | ||
package com.llgc; | package com.llgc; | ||
Ligne 122: | Ligne 125: | ||
</ | </ | ||
- | =====JSP/JSF===== | + | =====Ajout d'un validateur des attributs===== |
- | Sur le principe, il ne faut pas mélanger les JSP et JSF mais j'ai mis trop de temps à faire marcher cet exemple pour le perdre. | + | La méthode '' |
- | Il faut un projet dynamique avec le support des JSF mais la page est générée depuis une JSP. | + | <file java TagPersoExtra.java> |
- | + | ||
- | <file xml faces-config.xml> | + | |
- | <?xml version=" | + | |
- | < | + | |
- | xmlns: | + | |
- | xsi: | + | |
- | version=" | + | |
- | < | + | |
- | < | + | |
- | < | + | |
- | < | + | |
- | < | + | |
- | </ | + | |
- | < | + | |
- | < | + | |
- | < | + | |
- | < | + | |
- | < | + | |
- | < | + | |
- | </ | + | |
- | </ | + | |
- | </ | + | |
- | </ | + | |
- | + | ||
- | <file java TagHeure.java> | + | |
package com.llgc; | package com.llgc; | ||
- | import | + | import |
- | import javax.faces.webapp.UIComponentELTag; | + | |
- | // Le nom de cette classe correspond avec celui défini dans le fichier tld, rubrique tag-class. | + | import javax.servlet.jsp.tagext.TagData; |
- | public class TagHeure extends UIComponentELTag | + | import javax.servlet.jsp.tagext.TagExtraInfo; |
- | { | + | |
- | private String label; | + | |
- | public String getLabel () | + | public class TagPersoExtra |
- | { | + | |
- | return label; | + | |
- | } | + | |
- | + | ||
- | public void setLabel (String label) | + | |
- | { | + | |
- | this.label = label; | + | |
- | } | + | |
- | + | ||
- | @Override | + | |
- | public String getComponentType () | + | |
- | { | + | |
- | // Le nom du type du composant correspond avec celui défini dans le fichier faces-config.xml, | + | |
- | // rubrique component|component-type | + | |
- | return " | + | |
- | } | + | |
- | + | ||
- | @Override | + | |
- | public String getRendererType () | + | |
- | { | + | |
- | // Le nom du rendu du composant correspond avec celui défini dans le fichier faces-config.xml, | + | |
- | // rubrique render-kit|renderer|renderer-type | + | |
- | return " | + | |
- | } | + | |
- | + | ||
- | @Override | + | |
- | protected void setProperties (UIComponent composant) | + | |
- | { | + | |
- | composant.getAttributes().put(" | + | |
- | super.setProperties (composant); | + | |
- | } | + | |
- | + | ||
- | } | + | |
- | </ | + | |
- | + | ||
- | <file java TagHeureRenderer.java> | + | |
- | package com.llgc; | + | |
- | + | ||
- | import java.io.IOException; | + | |
- | import java.util.Calendar; | + | |
- | + | ||
- | import javax.faces.component.UIComponent; | + | |
- | import javax.faces.context.FacesContext; | + | |
- | import javax.faces.context.ResponseWriter; | + | |
- | import javax.faces.render.Renderer; | + | |
- | + | ||
- | public class TagHeureRenderer | + | |
{ | { | ||
@Override | @Override | ||
- | public | + | public |
{ | { | ||
- | | + | |
- | | + | |
- | | + | |
- | + calendrier.get (Calendar.SECOND); | + | |
- | ResponseWriter | + | |
- | out.write | + | |
- | + "</ | + | |
- | | + | |
- | } | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | <file java TagPerso.java> | + | |
- | package com.llgc; | + | |
- | + | ||
- | import java.io.IOException; | + | |
- | + | ||
- | import javax.servlet.jsp.JspException; | + | |
- | import javax.servlet.jsp.JspWriter; | + | |
- | import javax.servlet.jsp.tagext.TagSupport; | + | |
- | + | ||
- | @SuppressWarnings | + | |
- | public class TagPerso extends TagSupport | + | |
- | { | + | |
- | private String attribute1; | + | |
- | private String attribute2; | + | |
- | + | ||
- | public String getAttribute1 () | + | |
- | { | + | |
- | return attribute1; | + | |
- | } | + | |
- | + | ||
- | public void setAttribute1 (String attribute1) | + | |
- | { | + | |
- | this.attribute1 = attribute1; | + | |
- | } | + | |
- | + | ||
- | public String getAttribute2 () | + | |
- | { | + | |
- | return attribute2; | + | |
- | } | + | |
- | + | ||
- | public void setAttribute2 (String attribute2) | + | |
- | { | + | |
- | this.attribute2 = attribute2; | + | |
- | } | + | |
- | + | ||
- | @Override | + | |
- | public int doEndTag () throws JspException | + | |
- | { | + | |
- | try | + | |
{ | { | ||
- | | + | |
- | out.println ("."); | + | |
+ | { | ||
+ | return false; | ||
+ | } | ||
+ | System.out.println (it + " | ||
} | } | ||
- | | + | return |
- | { | + | |
- | e.printStackTrace (); | + | |
- | throw new JspException (e); | + | |
- | } | + | |
- | | + | |
- | } | + | |
- | + | ||
- | @Override | + | |
- | public int doStartTag () throws JspException | + | |
- | { | + | |
- | JspWriter out = pageContext.getOut | + | |
- | try | + | |
- | { | + | |
- | out.println (" | + | |
- | out.println ("Le corps du message : "); | + | |
- | } | + | |
- | catch (IOException e) | + | |
- | { | + | |
- | e.printStackTrace (); | + | |
- | throw new JspException (e); | + | |
- | } | + | |
- | return EVAL_BODY_INCLUDE; | + | |
} | } | ||
} | } | ||
</ | </ | ||
- | <file xml taglib2.jsp> | + | <file xml tagperso.tld> |
- | <%@ page language="java" | + | <?xml version="1.0" |
- | pageEncoding=" | + | <javaee:taglib |
- | <%@ taglib | + | xmlns:xml="http://www.w3.org/XML/1998/ |
- | <%@ taglib uri=" | + | |
- | + | <javaee: | |
- | < | + | <javaee: |
- | < | + | <javaee:tag> |
- | < | + | <javaee:name>nomtag</javaee:name> |
- | <meta http-equiv="Content-Type" | + | |
- | <title>Insert title here</title> | + | < |
- | </head> | + | … |
- | <body> | + | |
- | <f:view> | + | </javaee: |
- | <p> | + | |
- | | + | |
- | </p> | + | |
- | </f:view> | + | |
- | </body> | + | |
- | </html> | + | |
</ | </ | ||
- | Rendu : | + | <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 '' |
+ | </ | ||
+ | |||
+ | Rendu (si '' | ||
+ | {{: |
helloworld/web/java/taglib/jsp.1439485973.txt.gz · Dernière modification : 2015/08/13 19:12 de root