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?