1

While migrating a project from JavaServer Faces 2.1 / Java EE 5 to JavaServer Faces 2.2 / Java EE 7 web profile on GlassFish 4, I encountered invalid HTML code because of additional <html> ... </html> tags for every instance of a composite component in the JSF code.

Environment: Mojarra 2.2.0 (GlassFish 4.0), NetBeans 7.3.1, JDK 7

Steps to reproduce:

  • create a new "Java EE 7 Web" project with JavaServer Faces and choose JSF 2.2 server library
  • in index.html, select the HTML body text ("Hello from Facelets") and refactor into a composite component

Example source code:

index.html

<?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://xmlns.jcp.org/jsf/html"
      xmlns:ez="http://xmlns.jcp.org/jsf/composite/ezcomp">
    <h:head>
        <title>Facelet Title</title>
    </h:head>
    <h:body>
        <ez:test/>
    </h:body>
</html>

test.xhtml

<?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:cc="http://xmlns.jcp.org/jsf/composite">

    <!-- INTERFACE -->
    <cc:interface>
    </cc:interface>

    <!-- IMPLEMENTATION -->
    <cc:implementation>
        Hello from Facelets
    </cc:implementation>
</html>

Actual HTML output:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head id="j_idt2">
        <title>Facelet Title</title></head><body><html xmlns="http://www.w3.org/1999/xhtml">

    <!-- INTERFACE -->

    <!-- IMPLEMENTATION -->
        Hello from Facelets

</html></body>
</html>

This is not valid HTML as there is another <html> ... </html> present for the composite component. Is there an error in my JSF code?

mjn
  • 36,362
  • 28
  • 176
  • 378

1 Answers1

1

Try using

<ui:component
    xmlns="http://www.w3.org/1999/xhtml"
.....
>

See an example here: http://balusc.blogspot.co.uk/2013/01/composite-component-with-multiple-input.html

Ioannis Deligiannis
  • 2,679
  • 5
  • 25
  • 48
  • With this change (and adding the ui namespace declaration `xmlns:ui="http://xmlns.jcp.org/jsf/facelets"`) , the page renders an exception now: `java.lang.NullPointerException at java.util.concurrent.ConcurrentHashMap.putIfAbsent(ConcurrentHashMap.java:1144) at com.sun.faces.util.Cache.get(Cache.java:116) at com.sun.faces.application.view.FaceletViewHandlingStrategy.getComponentMetadata(FaceletViewHandlingStrategy.java:237) ...` – mjn Oct 24 '13 at 14:18
  • Are you using GF4? If so, I would strongly recommend updating the javax.faces jar with the latest one the apckaged one had quite a few bugs. Also did you follow the example above in terms of namespaces and setup? – Ioannis Deligiannis Oct 24 '13 at 14:30
  • Updating javax.faces to 2.2.4 fixed it, many thanks for the hint – mjn Oct 24 '13 at 16:10