在将项目从JavaServer Faces 2.1 / Java EE 5迁移到GlassFish 4上的JavaServer Faces 2.2 / Java EE 7 Web配置文件时,我遇到了无效的HTML代码,因为复合组件的每个实例都有额外的<html> ... </html>
标记在JSF代码中。
环境:Mojarra 2.2.0(GlassFish 4.0),NetBeans 7.3.1,JDK 7
重现的步骤:
示例源代码:
的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>
实际HTML输出:
<?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>
这不是有效的HTML,因为复合组件还有另一个<html> ... </html>
。我的JSF代码中是否有错误?
答案 0 :(得分:1)
尝试使用
<ui:component
xmlns="http://www.w3.org/1999/xhtml"
.....
>
请在此处查看示例:http://balusc.blogspot.co.uk/2013/01/composite-component-with-multiple-input.html