Error trying to add composite component programmatically ("no tag was defined for name")
<p>I'm facing one of those errors that you're almost sure that you're not doing anything wrong, but the error simply won't go away, no mather what you do.</p>

<p>I have this composite component:</p>

<p><strong>inputMask.xhtml</strong></p>

<pre><code>&lt;!DOCTYPE html&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:composite="http://xmlns.jcp.org/jsf/composite"
      xmlns:f="http://xmlns.jcp.org/jsf/core"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"&gt;

      &lt;composite:interface&gt;
        &lt;composite:attribute name="value" /&gt;
        &lt;composite:attribute name="mask" type="java.lang.String" required="true" /&gt;
        &lt;composite:attribute name="converterId" type="java.lang.String" default="br.edu.ufca.eventos.visao.inputmask.inputMask" /&gt;
      &lt;/composite:interface&gt;

      &lt;composite:implementation&gt;
        &lt;h:outputScript library="script" name="inputmask.js" target="head" /&gt;

        &lt;h:inputText id="mascara"&gt;
            &lt;c:if test="#{cc.getValueExpression('value') != null}"&gt;
                &lt;f:attribute name="value" value="#{cc.attrs.value}" /&gt;
            &lt;/c:if&gt;
            &lt;f:converter converterId="#{cc.attrs.converterId}" /&gt;
            &lt;f:attribute name="mask" value="#{cc.attrs.mask}" /&gt;
        &lt;/h:inputText&gt;

        &lt;h:outputScript target="body"&gt;
            defineMask("#{cc.clientId}", "#{cc.attrs.mask}");
        &lt;/h:outputScript&gt;
      &lt;/composite:implementation&gt;
&lt;/html&gt;
</code></pre>

<p>When I use it in a <em>xhtml</em> page like this:</p>

<pre><code>&lt;ui:composition template="layout.xhtml"
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
    xmlns:ec="http://xmlns.jcp.org/jsf/composite/componente"&gt;

    &lt;ui:define name="contents"&gt;
        &lt;ec:inputMask value="#{bean.cpf}" mask="999.999.999-99" /&gt;
    &lt;/ui:define&gt;
&lt;/ui:composition&gt;
</code></pre>

<p>Everything works fine. The component is rendered without problems and works well.</p>

<p>But when I try to add it programmatically, using OmniFaces <a href="http://omnifaces.org/docs/javadoc/2.4/org/omnifaces/util/Components.html#includeCompositeComponent-javax.faces.component.UIComponent-java.lang.String-java.lang.String-java.lang.String-java.util.Map-" rel="nofollow">Components#includeCompositeComponent</a>, like this:</p>

<pre><code>Map&lt;String, String&gt; attributes = new HashMap&lt;&gt;();
attributes.put("mask", "999.999.999-99");
Components.includeCompositeComponent(Components.getCurrentForm(), "componente", "inputMask.xhtml", "a123", attributes);
</code></pre>

<p>I get this error:</p>

<pre><code>javax.faces.view.facelets.TagException: //C:/wildfly-10/standalone/tmp/eventos.ear.visao.war/mojarra7308315477323852505.tmp @2,127 &lt;j:inputMask.xhtml&gt; Tag Library supports namespace: http://xmlns.jcp.org/jsf/composite/componente, but no tag was defined for name: inputMask.xhtml
    at com.sun.faces.facelets.compiler.CompilationManager.pushTag(CompilationManager.java:311)
    at com.sun.faces.facelets.compiler.SAXCompiler$CompilationHandler.startElement(SAXCompiler.java:266)
    at org.apache.xerces.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:498)
    at org.apache.xerces.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:180)
    at org.apache.xerces.impl.dtd.XMLDTDValidator.emptyElement(XMLDTDValidator.java:811)
    at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:275)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1653)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:324)
    at org.apache.xerces.parsers.XML11Configuration.parse(XML11Configuration.java:875)
    at org.apache.xerces.parsers.XML11Configuration.parse(XML11Configuration.java:798)
    at org.apache.xerces.parsers.XMLParser.parse(XMLParser.java:108)
    at org.apache.xerces.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1198)
    at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:564)
    at org.apache.xerces.jaxp.SAXParserImpl.parse(SAXParserImpl.java:298)
    at javax.xml.parsers.SAXParser.parse(SAXParser.java:195)
    at com.sun.faces.facelets.compiler.SAXCompiler.doCompile(SAXCompiler.java:454)
    at com.sun.faces.facelets.compiler.SAXCompiler.doCompile(SAXCompiler.java:430)
    at com.sun.faces.facelets.compiler.Compiler.compile(Compiler.java:124)
    at com.sun.faces.facelets.impl.DefaultFaceletFactory.createFacelet(DefaultFaceletFactory.java:481)
    at com.sun.faces.facelets.impl.DefaultFaceletFactory._createComponent(DefaultFaceletFactory.java:407)
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.createComponent(FaceletViewHandlingStrategy.java:842)
    at org.omnifaces.util.Components.includeCompositeComponent(Components.java:651)
    at br.edu.ufca.eventos.visao.PaginaLogin.autenticarUsuario(PaginaLogin.java:81)
    at br.edu.ufca.eventos.visao.PaginaLoginServidor.autenticarUsuario(PaginaLoginServidor.java:19)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.sun.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:181)
    at com.sun.el.parser.AstValue.invoke(AstValue.java:289)
    at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:304)
    at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
    at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
    at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
    at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
    at javax.faces.component.UICommand.broadcast(UICommand.java:315)
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:658)
    at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129)
    at br.edu.ufca.eventos.visao.ControladorAcessoFilter.doFilter(ControladorAcessoFilter.java:39)
    at org.omnifaces.filter.HttpFilter.doFilter(HttpFilter.java:108)
    at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
    at br.edu.ufca.eventos.visao.ControladorAcessoFilter.irParaPaginaLiberacaoAcesso(ControladorAcessoFilter.java:89)
    at br.edu.ufca.eventos.visao.ControladorAcessoFilter.doFilter(ControladorAcessoFilter.java:31)
    at org.omnifaces.filter.HttpFilter.doFilter(HttpFilter.java:108)
    at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
    at br.edu.ufca.eventos.visao.ErroFilter.doFilter(ErroFilter.java:28)
    at org.omnifaces.filter.HttpFilter.doFilter(HttpFilter.java:108)
    at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
    at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)
    at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
    at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
    at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
    at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
    at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
    at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
    at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
    at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
    at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292)
    at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81)
    at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138)
    at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)
    at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
    at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
    at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
    at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
    at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
    at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
    at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
    at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
    at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)
    at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
    at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104)
    at io.undertow.server.Connectors.executeRootHandler(Connectors.java:202)
    at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:805)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
</code></pre>

<p>I would like to have your help to solve this issue, because I've already tried many things but didn't have success.</p>

<p>I'm using <em>Wildfly 10.1.0.Final</em> (which comes with <em>Mojarra 2.2.13</em>)</p>

<p>PS.: I know Primefaces has an input mask component, but I wouldn't like to use Primefaces.</p>

<p><strong>---- UPDATE ----</strong></p>

<p>If I change the code to add the composite component to this (changing <code>inputMask.xhtml</code> to just <code>inputMask</code>):</p>

<pre><code>Components.includeCompositeComponent(Components.getCurrentForm(), "componente", "inputMask", "a123", attributes);
</code></pre>

<p>I get this error instead:</p>

<pre><code>Caused by: javax.faces.FacesException: Cannot remove the same component twice: form:a123:j_idt2
    at com.sun.faces.context.StateContext$DynamicAddRemoveListener.handleAddRemoveWithAutoPrune(StateContext.java:761)
    at com.sun.faces.context.StateContext$DynamicAddRemoveListener.handleRemove(StateContext.java:629)
    at com.sun.faces.context.StateContext$AddRemoveListener.processEvent(StateContext.java:342)
    at com.sun.faces.context.StateContext$DynamicAddRemoveListener.processEvent(StateContext.java:565)
    at javax.faces.event.SystemEvent.processListener(SystemEvent.java:108)
    at javax.faces.event.ComponentSystemEvent.processListener(ComponentSystemEvent.java:118)
    at com.sun.faces.application.ApplicationImpl.processListenersAccountingForAdds(ApplicationImpl.java:2218)
    at com.sun.faces.application.ApplicationImpl.invokeViewListenersFor(ApplicationImpl.java:2036)
    at com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:290)
    at com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:245)
    at org.jboss.as.jsf.injection.weld.ForwardingApplication.publishEvent(ForwardingApplication.java:299)
    at javax.faces.application.ApplicationWrapper.publishEvent(ApplicationWrapper.java:726)
    at javax.faces.component.UIComponentBase.disconnectFromView(UIComponentBase.java:2281)
    at javax.faces.component.UIComponentBase.doPreRemoveProcessing(UIComponentBase.java:1944)
    at javax.faces.component.UIComponentBase.setParent(UIComponentBase.java:436)
    at javax.faces.component.UIComponentBase$ChildrenList.remove(UIComponentBase.java:2775)
    at javax.faces.component.UIViewRoot.addComponentResource(UIViewRoot.java:528)
    at com.sun.faces.renderkit.html_basic.ScriptStyleBaseRenderer.processEvent(ScriptStyleBaseRenderer.java:105)
    at javax.faces.component.UIComponent$ComponentSystemEventListenerAdapter.processEvent(UIComponent.java:2584)
    at javax.faces.event.SystemEvent.processListener(SystemEvent.java:108)
    at javax.faces.event.ComponentSystemEvent.processListener(ComponentSystemEvent.java:118)
    at com.sun.faces.application.ApplicationImpl.processListeners(ApplicationImpl.java:2169)
    at com.sun.faces.application.ApplicationImpl.invokeComponentListenersFor(ApplicationImpl.java:2114)
    at com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:287)
    at com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:245)
    at org.jboss.as.jsf.injection.weld.ForwardingApplication.publishEvent(ForwardingApplication.java:299)
    at javax.faces.application.ApplicationWrapper.publishEvent(ApplicationWrapper.java:726)
    at javax.faces.component.UIComponentBase.publishAfterViewEvents(UIComponentBase.java:2254)
    at javax.faces.component.UIComponentBase.doPostAddProcessing(UIComponentBase.java:1935)
    at javax.faces.component.UIComponentBase.setParent(UIComponentBase.java:448)
    at javax.faces.component.UIComponentBase$ChildrenList.add(UIComponentBase.java:2700)
    at javax.faces.component.UIComponentBase$ChildrenList.add(UIComponentBase.java:2672)
    at javax.faces.component.UIViewRoot.addComponentResource(UIViewRoot.java:533)
    at com.sun.faces.renderkit.html_basic.ScriptStyleBaseRenderer.processEvent(ScriptStyleBaseRenderer.java:105)
    at javax.faces.component.UIComponent$ComponentSystemEventListenerAdapter.processEvent(UIComponent.java:2584)
    at javax.faces.event.SystemEvent.processListener(SystemEvent.java:108)
    at javax.faces.event.ComponentSystemEvent.processListener(ComponentSystemEvent.java:118)
    at com.sun.faces.application.ApplicationImpl.processListeners(ApplicationImpl.java:2169)
    at com.sun.faces.application.ApplicationImpl.invokeComponentListenersFor(ApplicationImpl.java:2114)
    at com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:287)
    at com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:245)
    at org.jboss.as.jsf.injection.weld.ForwardingApplication.publishEvent(ForwardingApplication.java:299)
    at javax.faces.application.ApplicationWrapper.publishEvent(ApplicationWrapper.java:726)
    at javax.faces.component.UIComponentBase.publishAfterViewEvents(UIComponentBase.java:2254)
    at javax.faces.component.UIComponentBase.publishAfterViewEvents(UIComponentBase.java:2259)
    at javax.faces.component.UIComponentBase.publishAfterViewEvents(UIComponentBase.java:2267)
    at javax.faces.component.UIComponentBase.doPostAddProcessing(UIComponentBase.java:1935)
    at javax.faces.component.UIComponentBase.setParent(UIComponentBase.java:448)
    at javax.faces.component.UIComponentBase$ChildrenList.add(UIComponentBase.java:2700)
    at javax.faces.component.UIComponentBase$ChildrenList.add(UIComponentBase.java:2672)
    at org.omnifaces.util.Components.includeCompositeComponent(Components.java:653)
    at br.edu.ufca.eventos.visao.PaginaLogin.autenticarUsuario(PaginaLogin.java:82)
    at br.edu.ufca.eventos.visao.PaginaLoginServidor.autenticarUsuario(PaginaLoginServidor.java:19)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.sun.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:181)
    at com.sun.el.parser.AstValue.invoke(AstValue.java:289)
    at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:304)
    at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
    at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
    at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
    at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
</code></pre>