本文介绍了封装了< html>的JavaServer Faces 2.2复合组件. ...</html>标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在GlassFish 4上将项目从JavaServer Faces 2.1/Java EE 5迁移到JavaServer Faces 2.2/Java EE 7 Web概要文件时,我遇到了无效的HTML代码,因为在该复合组件的每个实例中都有附加的<html> ... </html>标记. JSF代码.

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.

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

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

复制步骤:

  • 使用JavaServer Faces创建一个新的"Java EE 7 Web"项目,然后选择JSF 2.2服务器库
  • 在index.html中,选择HTML正文文本(来自Facelets的Hello")并重构为复合组件

示例源代码:

index.html

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

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代码中有错误吗?

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

推荐答案

尝试使用

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

在此处查看示例: http://balusc.blogspot.co.uk/2013/01/composite-component-with-multiple-input.html

这篇关于封装了&lt; html&gt;的JavaServer Faces 2.2复合组件. ...&lt;/html&gt;标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 16:16