我创建了一个 jsf 自定义标签(我不确定它是否正确,我很容易错过一些东西,所以我在下面附上了代码)。
现在我正在尝试使用此标签,但出现错误:
第 28 行第 49 列的错误:未定义甘特图上的命名空间前缀 gc
所以,这里是 xhtml 页面:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:gc="http://myganttchart.org">
<body>
<ui:composition template="/masterpage.xhtml">
<ui:define name="title">Gantt chart test</ui:define>
<ui:define name="content">
<f:view>
<gc:ganttchart width="300" height="100" rendered="true"/>
...
</f:view>
</ui:define>
</ui:composition>
</body>
</html>
这里是tld
-file (它被放置在WEB-INF/
):
<taglib xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.1">
<tlib-version>
1.0
</tlib-version>
<short-name>
oext
</short-name>
<uri>
http://myganttchart.org
</uri>
<tag>
<name>ganttchart</name>
<tag-class>usermanagement.support.ganttchart.GanttChartTag</tag-class>
<body-content>empty</body-content>
<attribute>
<name>binding</name>
<deferred-value>
<type>javax.faces.component.UIComponent</type>
</deferred-value>
</attribute>
...
</tag>
</tablib>
这是tag-class
代码的一部分:
public class GanttChartTag extends UIComponentELTag {
private ValueExpression width;
private ValueExpression height;
private ValueExpression styleClass;
public String getComponentType () {
return "org.myganttchart";
}
public String getRendererType () {
return null;
}
...
}
来自的通讯块faces-config
:
<component>
<component-type>org.myganttchart</component-type>
<component-class>usermanagement.support.ganttchart.UIGanttChart</component-class>
</component>
最后一部分如果UIGanttChart
:
public class UIGanttChart extends UIOutput {
public UIGanttChart() {
setRendererType (null);
}
//some test code
public void encodeBegin(FacesContext context) throws IOException {
ResponseWriter writer = context.getResponseWriter ();
writer.startElement("img", this);
writer.writeAttribute("src", "no-img", "source");
writer.writeAttribute("width", getAttributes ().get ("width"), "width");
writer.writeAttribute("height", getAttributes ().get ("height"), "height");
writer.writeAttribute("class", ".someclass", "styleClass");
writer.endElement("img");
}
}
那么,我错过了什么?欢迎任何关于如何调试或问题出在哪里的想法。