I migrated some of my facelets custom components into proper composite components, but encounters the following error while rendering a view that contains the composite component:
javax.faces.view.facelets.TagException: /WEB-INF/taglib/cctest.xhtml @15,26 <composite:interface> Component Not Found for identifier: bodyId.getParent().
at com.sun.faces.facelets.tag.composite.InterfaceHandler.validateComponent(InterfaceHandler.java:135)
at com.sun.faces.facelets.tag.composite.InterfaceHandler.apply(InterfaceHandler.java:125)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:95)
at com.sun.faces.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:93)
at com.sun.faces.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:87)
at com.sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:320)
at com.sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:379)
at com.sun.faces.facelets.impl.DefaultFaceletContext.includeFacelet(DefaultFaceletContext.java:326)
at com.sun.faces.facelets.tag.UserTagHandler.apply(UserTagHandler.java:142)
at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:137)
at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:187)
at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:95)
at com.sun.faces.facelets.tag.jsf.core.ViewHandler.apply(ViewHandler.java:188)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:95)
at com.sun.faces.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:93)
at com.sun.faces.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:87)
at com.sun.faces.facelets.impl.DefaultFacelet.apply(DefaultFacelet.java:164)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.buildView(FaceletViewHandlingStrategy.java:906)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.jav
In the error message, the name bodyId
refers to the id of <h:body>
in the file below, and getParent()
is hardcoded during the creation of the exception message. @15,26
refers to the end of <composite:interface>
in cctest.xhtml below.
Here is the page that contains the composite component:
<?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:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core"
xmlns:bam="http://bam.mycompany.com/jsftaglib"
>
<f:view locale="en" id="viewId">
<h:head id="headId">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Title</title>
</h:head>
<h:body id="bodyId">
<bam:cctest value="hello world."/>
</h:body>
</f:view>
</html>
Here is the file named cctest.xhtml
that declares the composite component cctest
:
<?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:composite="http://java.sun.com/jsf/composite"
xmlns:h="http://java.sun.com/jsf/html"
>
<h:head>
<title>not used</title>
</h:head>
<h:body>
<composite:interface>
<composite:attribute name="value" required="true"/>
</composite:interface>
<composite:implementation>
<h:outputText id="text_#{cc.attrs.value}" value="#{cc.attrs.value}"/>
</composite:implementation>
</h:body>
</html>
The composite component is declared in a file named bam.taglib.xml located in /WEB-INF/taglib/, next to cctext.xhtml
. Here is the file:
<facelet-taglib 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"
version="2.0">
<namespace>http://bam.mycompany.com/jsftaglib</namespace>
<tag>
<tag-name>cctest</tag-name>
<source>cctest.xhtml</source>
</tag>
</facelet-taglib>
I'm using mojarra 2.1.21 into tomcat 7.0.41. My faces-config.xml file is empty, there's no managed beans or other custom-defined components (validator, etc.). Web.xml only declares a few context param, plus the faces servlet mapped on *.xhtml; here are those context parameters:
- javax.faces.FACELETS_REFRESH_PERIOD = 1
- javax.faces.FACELETS_SKIP_COMMENTS = false
- javax.faces.FACELETS_LIBRARIES = /WEB-INF/taglib/bam.taglib.xml
- javax.faces.PROJECT_STAGE = Development
- javax.faces.VALIDATE_EMPTY_FIELDS = false
- javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL = true
Looking at the component tree that is displayed in the facelets error page, there's no element named bodyId
, which might be a hint for my issue. A copy of which is displayed below:
<UIViewRoot id="j_id1" inView="true" locale="en" renderKitId="HTML_BASIC" rendered="true" transient="false" viewId="/pages/composite_component_test.xhtml">
<html xmlns="http://www.w3.org/1999/xhtml">
<UIOutput id="headId" inView="true" rendered="true" transient="false">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <title>Title</title>
</UIOutput>
</UIViewRoot>
Many thanks in advance for looking at this issue.
JSF 2.0 composite componenets
doesn't need to be loaded through.xml
file . Follow this post mkyong.com/jsf2/composite-components-in-jsf-2-0 to implement yourCCs
– SRy