[英]Why do I get error “prefix [..] is not defined” when I try to use my jsf custom tag?
I created a jsf custom tag (I'm not sure that it's correct, I could miss something easily, so I attached code below). 我创建了一个jsf自定义标签(我不确定它是否正确,我可能很容易错过,所以我在下面附上代码)。
Now I'm trying to use this tag but I get an error: 现在我正在尝试使用此标记但是我收到错误:
error on line 28 at column 49: Namespace prefix gc on ganttchart is not defined 第49行第28行的错误:未定义ganttchart上的命名空间前缀gc
So, here is the xhtml-page: 所以,这是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>
And here is tld
-file (it's placed in WEB-INF/
): 这里是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>
Here is a part of tag-class
code: 这是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;
}
...
}
Correspondent block from faces-config
: 来自faces-config
通讯块:
<component>
<component-type>org.myganttchart</component-type>
<component-class>usermanagement.support.ganttchart.UIGanttChart</component-class>
</component>
And the last part if UIGanttChart
: 最后一部分如果是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");
}
}
So, what did I miss? 那么,我错过了什么? Any ideas about how to debug or where can be the problem are welcome. 任何有关如何调试或在哪里可能是问题的想法都是受欢迎的。
You need to define your new taglib a-la-facelets. 您需要定义新的taglib a-la-facelets。
Create a file called "gc.taglib.xml" under /WEB-INF 在/ 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>
And keep what you did with faces-config.xml
. 并使用faces-config.xml
保留你所做的。
You're using Facelets, but defining a JSP tag. 您正在使用Facelets,但定义了JSP标记。 Facelets have their own tag definition files (with a .taglib.xml
suffix). Facelets有自己的标记定义文件(后缀为.taglib.xml
)。
If you're using JSF 1.2 with Facelets, you'll find the DTD here . 如果你正在使用带有Facelets的JSF 1.2,你可以在这里找到DTD。 If you're using JSF 2.0, a schema is defined in the JSR 314 spec (Appendix A, section 1.2). 如果您使用的是JSF 2.0,则在JSR 314规范中定义了一个模式(附录A,第1.2节)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.