Question

I encountered a strange error while working on a page which uses a composite component inside a <ui:include> tag. I have a single page testCC.xhtml, with the following contents:

  1. <ui:include> pointing to a testCC_inc.xhtml file which itself contains a composite component.
  2. <h:inputText> wrapping a <f:validate> tag containing a facelet function in one of its attributes.

When the page is rendered, I get the following exception "Function 'fn:plusOne' not found". The funny part is when I try to change things in the page:

  1. Move <ui:include> tag after <h:inputText> : works fine.
  2. Move facelet function invocation in the value attribute of <h:inputText> (and replace the function with a litteral in <f:validate>) : works fine.
  3. Remove the composite component from the included page : works fine.

While debugging into EL (=jasper-el since I'm on tomcat) and facelets taglib, I noticed a major difference between the failing situation and one of the working situations from above : While trying to resolve the facelet function, the map of available namespaces to look into is the one from the included file !! However, adding namespaces from the main page into the included page did not solve my issue.

I surely missed something or did something wrong in my pages/configuration, but could not figure it out.

My config

  • jdk 1.7.0_25
  • tomcat 7.0.41 with system property org.apache.el.parser.COERCE_TO_ZERO=false
  • mojarra 2.1.21

web.xml contains solely the FacesServlet mapped to *.xhtml + the following context-params:

  • javax.faces.FACELETS_REFRESH_PERIOD = 1
  • javax.faces.FACELETS_SKIP_COMMENTS = false
  • javax.faces.FACELETS_LIBRARIES = /WEB-INF/taglibs/functions.taglib.xml. The file that declares namespace http://my.company.com/functions and contains the facelet function int plusOne(int).
  • javax.faces.PROJECT_STAGE = Development
  • javax.faces.VALIDATE_EMPTY_FIELDS = false
  • javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL = true

faces-config.xml is empty, no other config files are loaded.

No managed beans, components, or any annotated classes.

No third-party JSF lib.

The files

webapp/testCC.xhtml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:fn="http://my.company.com/functions">
<f:view>
  <h:head>
    <meta http-equiv="cache-control" content="no-cache" />
  </h:head>
  <h:body>
    <h:form id="f">
      <h1>Test CC</h1>
      <ui:include src="testCC_inc.xhtml"/>
      <h:inputText id="inputText">
        <f:validateLength maximum="#{fn:plusOne(42)}" />
      </h:inputText>
    </h:form>
  </h:body>
</f:view>
</html>

webapp/testCC_inc.xhtml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:mycc="http://java.sun.com/jsf/composite/test">
<ui:composition>
   <mycc:dummycc echo="OK"/>
</ui:composition>
</html>

webapp/resources/test/dummycc.xhtml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html >
<html xmlns="http://www.w3.org/1999/xhtml" 
  xmlns:cc="http://java.sun.com/jsf/composite"
  xmlns:h="http://java.sun.com/jsf/html">
  <h:head/>
  <h:body>
    <cc:interface>
      <cc:attribute name="echo" required="true"/>
    </cc:interface>
    <cc:implementation>
      #{cc.attrs.echo}
    </cc:implementation>
  </h:body>
</html>
Was it helpful?

Solution

This is recognizable as Mojarra issue 2437, which can be workarounded by redeclaring the XML namespace in the composite's implementation as follows:

<cc:implementation xmlns:fn="http://my.company.com/functions">

However, this issue was already fixed in Mojarra 2.1.10 and yet you mentioned that you're using 2.1.21. I'd re-verify if you're really running Mojarra 2.1.21 or at least upgrade it to the current latest available version 2.1.26.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top