【问题标题】:Does the component-type name needs to be unique for custom components?自定义组件的组件类型名称是否需要唯一?
【发布时间】:2016-07-03 14:32:40
【问题描述】:

我是 自定义组件 主题的新手,从 JSF 2.2 开始

但是,我首先考虑JSF2.0的情况

考虑sn-p:

@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.xmlWEB_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>

以上两个示例都是同一个网络应用程序的一部分,并且工作正常。 但是,如果我在第二种情况下更改组件类型名称以使其与第一种情况相同,

@FacesComponent("components.WelcomeComponent1")

我明白了-

警告:此页面调用 XML 命名空间 http://xmlns.jcp.org/jsf/component 声明了前缀 t 但没有 该命名空间存在标记库

显然taglib.xml 中声明的条目/标签是首选。

因此,组件类型名称在每种情况下都需要唯一。对吧?

我很清楚命名空间http://xmlns.jcp.org/jsf/component 是与JSF2.2 一起引入的。

【问题讨论】:

    标签: jsf jsf-2.2 custom-component


    【解决方案1】:

    简短的回答是,它应该是唯一的。 JSF 将其视为自定义组件的名称(类似于@ManagedBean)。基本上,组件类型允许Application 实例使用定义的组件类型和createComponent() 方法创建UIComponent 子类(您和所有其他自定义组件)的新实例。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-08
      • 1970-01-01
      相关资源
      最近更新 更多