Search code examples
jsf-2faceletsfacelet-tag

JSF2 custom component issue


I have created a custom component which is used in xhtml view and it takes the attribute value and print it(like helloworld in below code), in JSF 2.1, using Netbeans8.1 and glassfish4.1. I have created a custom component by extending UIComponentBase overridden family and encode begin and custom component tag class by extending UIComponentELTag overriding componentType and rendererType methods. I have defined a tag library for it test.taglib.xml and registered it in web.xml.

Below is the view code.

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:body>

    <h2>JSF Custom Input FacesComponent Example</h2>
    <h:form>
        <ui:composition 
                   xmlns:custom="http://packt.net/cookbook/components"
                        xmlns:ui="http://java.sun.com/jsf/facelets">
            <custom:testInput helloworld="test component!!"/>
        </ui:composition>
    </h:form>

</h:body>
</html>

The problem is - it is only displaying the html value and not displaying the custom component attribute value.

The same example works for when I tried for jsp view (with tld file).

I tried using custom component tag directly or as child of ui:composition but no luck.

I put a break point in the custom component and tried to debug, but control is not even going to the break point.

Since control is not going to break point, so does it means my custom component is not getting registered by the servlet? If so them please tell me what I am doing wrong.

I am new to JSF so please tell me if I am missing any point.

I tried the same with JSF2.2.7 but that also exhibits the same problem.


Solution

  • I cannot find the root cause but got my problem solved. I tried the same code with JSF 2.2.7 jar but I used annotations instead. As mentioned in the problem that it didn't worked with 2.2.7, was because I was using old fashion code, like creating taglib and updating it in deployment descriptor.