简体   繁体   English

当我尝试使用我的jsf自定义标记时,为什么会出现错误“前缀[..]未定义”?

[英]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.

相关问题 当我尝试保存测试计划时,为什么会出现 NoClassDefFound 错误? - Why do I get a NoClassDefFound error when I try to save my test plan? 当我尝试使用 Jsoup 在我的 class 中获取多个文档时,为什么会出现 handshake_failure 错误? - Why do I get a handshake_failure error when I try to get more than 1 Document in my class using Jsoup? 为什么我在使用弹簧输入标签时会出错 - Why i get error when use spring input tag 如果尝试在视图类中将值放入映射中,为什么会出现错误? - Why do I get an error if I try to put values into a map in my view class? 当我尝试编译我的 Java 代码时,为什么会得到“异常;必须被捕获或声明被抛出”? - Why do I get "Exception; must be caught or declared to be thrown" when I try to compile my Java code? 当我尝试从Jframe中的表中获取字符串时,为什么会出现错误? - Why am I getting an error when I try to get a string from my table in a Jframe? 当我尝试在库存外部/没有物品的库存中单击时,为什么会出现错误? - Why do I get an error when I try to click outside the inventory / in the inventory where there's no item 为什么在尝试输出数组时会出现异常错误? - Why do I get an exception error when I try output an array? 当我尝试在基类方法中调用子类方法时,为什么会出现错误? - Why do I get an error when I try to call a subclass method inside a baseclass method? 当我尝试使用具有相同名称和参数类型的两个方法时,为什么会出现编译错误? - Why do I get a compilation error when I try to have two methods with the same name and parameter type?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM