I'm creating a custom tag in my application but for some reason it's not working, I followed this tutorial (which is the clearest one that I found to put here as reference) but, like other tutorials that I did, my custom tag ins not called.
WEB-INF/example.taglib.xml
<?xml version="1.0" encoding="UTF-8"?>
<facelet-taglib
xmlns="http://java.sun.com/xml/ns/javaee"
version="2.0">
<namespace>http://example.com/facelettags</namespace>
<tag>
<tag-name>hello</tag-name>
<handler-class>example.MenuTagHandler</handler-class>
</tag>
</facelet-taglib>
My tag handler class
package example;
public class MenuTagHandler extends TagHandler {
private String name = "Anonymous";
public MenuTagHandler(TagConfig config) {
//other constructor stuff
Logger.getLogger(MenuTagHandler.class).info("aaaa");
//other constructor stuff
}
@Override
public void apply(FaceletContext context, UIComponent parent) throws IOException {
Logger.getLogger(MenuTagHandler.class).info("aaaa");
UIComponentBase c = new UIComponentBase() {
@Override
public void encodeEnd(FacesContext ctx) throws IOException {
ResponseWriter w = ctx.getResponseWriter();
w.write(String.format(
"<p>Hello %s! I am FaceletTag.</p>",
name));
}
// abstract method in base, must override
@Override
public String getFamily() {
return "com.example.facelettag.test";
}
};
parent.getChildren().add(c);
}
}
My .xhtml file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:exampler="http://example.com/facelettags" >
<example:hello />
</ui:composition>
The rendered result is
<example:hello></example:hello>
Unfortunately nothing is printed in the log, does anyone have any idea on why it is not calling the tag handler?