2016-07-03 13 views
1

は私が私が最初のスニペットを検討JSF2.0コンポーネントタイプの名前は、カスタムコンポーネントで一意である必要がありますか?

のケースを検討しています、2.2

しかしJSFで始まるカスタムコンポーネントトピックに新しいです:

@FacesComponent(value = "components.WelcomeComponent1", createTag = true) 
public class WelcomeComponent extends UIComponentBase { 

} 

は予告行いをvalue = "components.WelcomeComponent1"

をUIワイヤフレームで参照しています。

<html xmlns="http://www.w3.org/1999/xhtml" 
     xmlns:h="http://xmlns.jcp.org/jsf/html" 
     xmlns:t="http://xmlns.jcp.org/jsf/component"> 
    <h:head> 
     <title></title> 
    </h:head> 
    <h:body>  
     <t:welcomeComponent value="Welcome" to="Rafael Nadal"/> 
    </h:body> 
</html> 

は、最初の場合のようにクラスの同じ名前と第二ケースを考えるが、異なる成分型名異なるパッケージで:

@FacesComponent("components.WelcomeComponent") 
public class WelcomeComponent extends UIComponentBase { 
      // code goes here 
} 

"components.WelcomeComponent"に気づくでください

taglib.xml WEB_INF

<namespace>http://atp.welcome.org/welcome</namespace> 

    <tag> 
     <tag-name>welcome</tag-name> 
     <component> 
      <component-type>components.WelcomeComponent</component-type> 
     </component> 

     <attribute> 
      <name>id</name> 
      <type>java.lang.String</type> 
      <description>Component id</description> 
      <required>false</required> 
     </attribute> 


    </tag> 

</facelet-taglib> 

、後者を参照 -

<html xmlns="http://www.w3.org/1999/xhtml" 
     xmlns:h="http://xmlns.jcp.org/jsf/html" 
     xmlns:t="http://atp.welcome.org/welcome"> 
    <h:head> 
     <title></title> 
    </h:head> 
    <h:body> 
     <t:welcome value="Welcome" to=""/>   
    </h:body> 
</html> 

上記の例の両方が同じウェブアプリケーション&作業微細の一部です。 XML名前空間 のためのこのページでコール:私は

@FacesComponent("components.WelcomeComponent1") 

、最初のケースのように、それは同じにするために後者の場合にはコンポーネント型の名前を変更した場合 は、しかし、私は

警告をGET-行いますプレフィックストンしかし、誰 タグライブラリを使用して宣言http://xmlns.jcp.org/jsf/componentは、その名前空間

明らかtaglib.xmlで宣言されたエントリ/タグが好まれるために存在します。だから、

、それぞれの場合にユニークにする必要がありコンポーネント型名。右?

名前空間http://xmlns.jcp.org/jsf/componentJSF2.2で導入されていることはよくわかっています。

答えて

2

短い回答ははいです。これは一意である必要があります。 JSFはカスタムコンポーネントの名前と考えています(@ManagedBeanと同様の方法で)。基本的には、コンポーネントタイプを使用すると、Applicationインスタンスは、定義されたコンポーネントタイプとcreateComponent()メソッドを使用して、UIComponentサブクラス(あなたと他のすべてのカスタムコンポーネント)の新しいインスタンスを作成できます。

関連する問題