1

I'm trying to create a custom taglib to use it on some projects. When I try to use it on the project, it works well. If I put the WAR in other projects, NetBeans detect its namespace and values, but when page is rendered, it throws:

"Warning: This page calls for XML namespace http://test.com/test declared with prefix te but no taglibrary exists for that namespace."

The code is based on some blogs I've found. Here is the "taglib project" structure:

WEB-INF
 |-- componentes
 |    `-- outputText.xhtml
 |-- test.taglib.xhtml
 `-- web.xml

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    <context-param>
        <param-name>javax.faces.FACELETS_LIBRARIES</param-name>
        <param-value>/WEB-INF/test.taglib.xml</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>index.xhtml</welcome-file>
    </welcome-file-list>
</web-app>

test.taglib.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE facelet-taglib PUBLIC
"-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN"
"http://java.sun.com/dtd/facelet-taglib_1_0.dtd">
<facelet-taglib version="2.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facelettaglibrary_2_0.xsd">
    <namespace>http://test.com/test</namespace>
    <tag>
        <tag-name>outputText</tag-name>
        <source>componentes/outputText.xhtml</source>
        <attribute>
            <description>Valor</description>
            <name>value</name>
        </attribute>
        <attribute>
            <description>Establece negrita</description>
            <name>negrita</name>
            <type>java.lang.Boolean</type>
        </attribute>
    </tag>
</facelet-taglib>

outputText.xhtml "hello world" example

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:ui="http://java.sun.com/jsf/facelets">

    <ui:composition>
        <h:outputText value="#{value}" style="#{negrita ? 'font-weight: bold' : '' }"/>
    </ui:composition>

</html>

Using taglib (on both "taglib project" and "taglib tester project" is the same):

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:te="http://test.com/test"
  >
    <h:head>
        <title>Pruebas componentes</title>
    </h:head>
    <h:body>
        <te:outputText value="Prueba te" negrita="true"/>
    </h:body>
</html>

Any ideas?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • What exactly do you mean with *"If I put the WAR in other projects"* ? Aren't you actually trying to create a reusable module project which should end up as a JAR file in `/WEB-INF/lib` of other WAR projects? – BalusC Feb 28 '15 at 13:05
  • Yes, that's what I want. If you import the "module project" as a library in other projects, they see the namespace, components and its attributes, but they aren't rendered. Instead, it throws the "no taglibrary exists " error on web browser. – Rafael Alcaide Feb 28 '15 at 13:38

1 Answers1

2

The project should be created as a "web fragment" project with the web resources such as the .taglib.xml file but also faces-config.xml in the project's /META-INF folder.

CommonWebProject
 |-- META-INF
 |    |-- tags
 |    |    |-- foo.xhtml
 |    |    |-- bar.xhtml
 |    |    :
 |    |
 |    |-- faces-config.xml
 |    |-- test.taglib.xml
 |    |-- web-fragment.xml
 |    `-- MANIFEST.MF
 :

When placing such a project as a JAR in /WEB-INF/lib of WAR, the entire javax.faces.FACELETS_LIBRARIES entry in web.xml of WAR is unnecessary.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555