Question

My custom components are currently declared in a custom taglib.xml file, and some of them need a handler, for example:

<tag>
    <tag-name>mycomponent</tag-name>
    <component>
        <component-type>com.so.MyComponent</component-type>
        <renderer-type>com.so.MyComponentRenderer</renderer-type>
        <handler-class>com.so.MyComponentHandler</handler-class>
    </component>
</tag>

Now I'd like to benefit from the new JSF 2.2 annotation-based declaration, writing:

@FacesComponent(value = MyComponent.COMPONENT_TYPE, tagName = "mycomponent", createTag = true)
public class MyComponent {

...but I can't figure out how to attach the component handler to this class. Is there any annotation for the handler class ?

Many thanks in advance!

Was it helpful?

Solution

I also ran into this issue trying to upgrade to JSF 2.2. I discovered that the web-facelettaglibary_2_2.xsd has a bug, and doesn't match the Mojarra 2.2.* implementation. See https://java.net/jira/browse/JAVASERVERFACES-3762.

Therefore, if you need to define a handler-class for a component, you still need to define the handler-class element in your taglib file, as you have specified in your question. In addition, you'll have to downgrade your xsd schema to web-facelettaglibrary_2_0.xsd.

Note that the expansion of @FacesComponent via JSF 2.2 hasn't removed the need to use a taglib file. The component handler-class is one example. Marking a tag attribute as required is another.

Best practices still dictate that all components have entries in the taglib file so that they are properly documented for contextual help. And since the taglib entry requires tag-name and component-type, you should not use @FacesComponent to define those for each component. That'll be more bug prone.

Thus, in your example, your best bet is to stick with using:

@FacesComponent(MyComponent.COMPONENT_TYPE)
public class MyComponent {
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top