3

jsfカスタムタグを作成しました(正しいかどうかはわかりません。何かを見逃しやすいので、以下のコードを添付しました)。

このタグを使用しようとしていますが、エラーが発生します。

行28の列49のエラー:ガントチャートの名前空間プレフィックスgcが定義されていません

それで、ここに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-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");
    }

}

それで、私は何を逃しましたか?デバッグの方法や問題が発生する可能性のある場所についてのアイデアは大歓迎です。

4

2 に答える 2

3

新しい taglib a-la-facelets を定義する必要があります。

/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

于 2010-04-27T07:46:46.397 に答える
2

Facelets を使用していますが、JSP タグを定義しています。Facelets には独自のタグ定義ファイルがあります (.taglib.xmlサフィックス付き)。

Facelets で JSF 1.2 を使用している場合は、ここに DTD があります。JSF 2.0 を使用している場合、スキーマはJSR 314 仕様(付録 A、セクション 1.2) で定義されています。

于 2010-04-26T17:50:19.037 に答える