java-为什么在尝试使用jsf自定义标记时出现错误“前缀[..]未定义”?
作者:互联网
我创建了一个jsf自定义标签(我不确定它是否正确,我很容易错过某些内容,因此在下面附加了代码).
现在,我正在尝试使用此标记,但出现错误:
error on line 28 at column 49:
Namespace prefix gc on ganttchart is
not defined
因此,这是xhtml-page:
<!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文件(放在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>
这是标记类代码的一部分:
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");
}
}
所以,我想念什么?欢迎提供有关如何调试或问题可能出在哪里的任何想法.
解决方法:
您需要定义新的taglib原样.
在/ WEB-INF下创建一个名为“ gc.taglib.xml”的文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE facelet-taglib PUBLIC "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN"
"https://facelets.dev.java.net/source/browse/*checkout*/facelets/src/etc/facelet-taglib_1_0.dtd">
<facelet-taglib>
<namespace>http://org.myganttchart/gc</namespace>
<tag>
<tag-name>gantchart</tag-name>
<component>
<component-type>org.myganttchart</component-type>
</component>
</tag>
</facelet-taglib>
并保留对faces-config.xml所做的操作.
标签:custom-component,jsf,facelets,java,java-ee 来源: https://codeday.me/bug/20191024/1917990.html