我在我的应用程序中创建了一个自定义标签,但由于某种原因它不起作用,我按照本教程(这是我发现放在这里作为参考的最清晰的教程)但是,就像我做的其他教程一样,我的自定义标签不叫。
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>
我的标签处理程序类
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);
}
}
我的 .xhtml 文件
<?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>
渲染的结果是
<example:hello></example:hello>
不幸的是,日志中没有打印任何内容,有人知道它为什么不调用标签处理程序吗?