1
votes

I am new to Custom components topic starting with JSF 2.2

However, I am first considering the case with JSF2.0

Consider the snippet:

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

}

Do notice value = "components.WelcomeComponent1"

referencing it in the UI wireframe-

<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>

Consider the second case with the same name of the class as in first case but in a different package with a different component-type name:

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

Do notice the "components.WelcomeComponent"

taglib.xml in 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>

and referencing the latter -

<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>

Both of the above examples are part of the same web app & work fine. However if I change the component-type name in the second case to make it the same as in first case,

@FacesComponent("components.WelcomeComponent1")

I do get-

Warning: This page calls for XML namespace http://xmlns.jcp.org/jsf/component declared with prefix t but no taglibrary exists for that namespace

Clearly the entry/tag declared in taglib.xml is preferred.

So, the component-type name needs to be unique in each case. Right?

I know it very well that the namespace http://xmlns.jcp.org/jsf/component was introduced with JSF2.2.

1

1 Answers

2
votes

Short answer is yes, it should be unique. JSF thinks of it as a name for your custom component (in the similar way as a @ManagedBean). Basically, component-type allows Application instance to create new instances of UIComponent subclasses (your and every other custom component) by using defined component-type and createComponent() method.