【问题标题】:Component ID form:composite:j_id2 has already been found in the view组件 ID form:composite:j_id2 已在视图中找到
【发布时间】:2011-12-28 05:58:27
【问题描述】:

/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:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:composite="http://java.sun.com/jsf/composite/components">
    <f:view>

        <h:head>
            <title>Default Title</title>
        </h:head>

        <h:body>
            <h:form id="form">
                <composite:test id="composite"/>
            </h:form>
        </h:body>

    </f:view>

</html>

/resources/components/test.xhtml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:cc="http://java.sun.com/jsf/composite"
      xmlns:composite="http://java.sun.com/jsf/composite/components"
      xmlns:p="http://primefaces.org/ui">

    <head>
        <title>(For validation only)</title>
    </head>

    <body>
    <cc:interface>
    </cc:interface>

    <cc:implementation>

        <p:panel header="header foo bar">

            <p:panel>
                <f:facet name="header">
                    <h:outputText value="foo"/>

                    <h:outputText value="bar"/>
                </f:facet>
            </p:panel>

        </p:panel>

    </cc:implementation>

</body>

</html>

这种组合给出:

GRAVE: Error Rendering View[/test.xhtml]
java.lang.IllegalStateException: Component ID form:composite:j_id2 has already been found in the view.  

用这棵树:

GRAVE: JSF1007: Duplicate component ID form:composite:j_id2 found in view.
GRAVE: +id: j_id1
 type: javax.faces.component.UIViewRoot@47080ae5
  +id: javax_faces_location_HEAD
   type: com.sun.faces.component.ComponentResourceContainer@2daf59b3
    +id: j_id3
     type: javax.faces.component.UIOutput@532a0e33
    +id: j_id4
     type: javax.faces.component.UIOutput@6e0a60ec
    +id: j_id5
     type: javax.faces.component.UIOutput@6b615e64
    +id: j_id6
     type: javax.faces.component.UIOutput@457c2e4f
    +id: j_id7
     type: javax.faces.component.UIOutput@5bc4682c
    +id: j_id8
     type: javax.faces.component.UIOutput@3b934fc5
  +id: j_idt37
   type: <?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">
  +id: j_idt38
   type: <html xmlns="http://www.w3.org/1999/xhtml">

  +id: j_idt39
   type: javax.faces.component.UIOutput@610364d1
    +id: j_idt40
     type: 
            <title>Default Title</title>

  +id: j_idt55
   type: javax.faces.component.UIOutput@25d00719
    +id: form
     type: javax.faces.component.html.HtmlForm@7c820db3
      +id: composite
       type: javax.faces.component.UINamingContainer@3e51a2a1
        +id: j_id2
         type: javax.faces.component.UIPanel@445a2d11
          +id: j_idt52
           type: org.primefaces.component.panel.Panel@618c17fd
            +id: j_idt53
             type: org.primefaces.component.panel.Panel@347b1513
              +id: j_id2
               type: javax.faces.component.UIPanel@7c44da25
                +id: j_idt50
                 type: javax.faces.component.html.HtmlOutputText@7ca4ad4f
                +id: j_idt54
                 type: javax.faces.component.html.HtmlOutputText@1f6e5d77
  +id: j_idt47
   type: 
</html>

但是,如果我以这种方式更改复合组件:

/resources/components/test.xhtml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:cc="http://java.sun.com/jsf/composite"
      xmlns:composite="http://java.sun.com/jsf/composite/components"
      xmlns:p="http://primefaces.org/ui">

    <head>
        <title>(For validation only)</title>
    </head>

    <body>
    <cc:interface>
    </cc:interface>

    <cc:implementation>

        <p:panel header="header foo bar">

            <p:panel>
                <f:facet name="header">
                    <h:panelGroup>
                        <h:outputText value="foo"/>

                        <h:outputText value="bar"/>
                    </h:panelGroup>
                </f:facet>
            </p:panel>

        </p:panel>

    </cc:implementation>

</body>

</html>

&lt;f:facet&gt; 中添加&lt;h:panelGroup&gt; 可以解决问题。 糟糕的树索引还是我错过了什么?我在 Glassfish 3.1.1 下使用 mojarra 2.1.3 和 PrimeFaces 3.0.M4-SNAPSHOT。

【问题讨论】:

  • 我现在正面临着类似的问题,因此非常感谢有关究竟是什么导致问题的相关信息。

标签: jsf-2 duplicates composite-component


【解决方案1】:

关于错误 JSF1007,请查看:artilce

【讨论】:

  • 小学,亲爱的华生。这样的答案有什么附加价值?
【解决方案2】:

根据 JSF2 文档,&lt;f:facet&gt; 标签只能有一个孩子。如果您有许多元素要嵌套在构面标记中,则应首先将它们包装在其他容器中,例如 &lt;h:panelGroup&gt;,然后将该单个父容器放入 &lt;f:facet&gt;

正是你所做的!

这是参考:

JavaServer Faces 2.0, The Complete Reference - 作者:Ed Burns、Chris Schalk

(ISBN-10:0071625097 | ISBN-13:978-0071625098)

页码:538

摘要:

f:facet 标签表示一个嵌套组件,它有一个特殊的 与其封闭标签的关系。例如,声明 表格的“标题”将由 JSF 组件提供。这个元素 在其主体中添加由 JSF 操作表示的组件作为 具有指定名称的构面到由 最接近的 JSF 组件父操作元素。这个标签只允许一个 嵌套在自身内部的组件。 使用多个组件作为 facet,将它们创建为简单容器组件的子组件。为了 例如,将相应的 HTML 库组件操作嵌套在 body 是一个 panelGroup 组件。

【讨论】:

  • 我不知道你有什么样的文档,但我在任何地方都找不到这个东西。希望不是“Marashi 2.0”...
  • @animanera 你说得对,它不在 oracle 官方参考文献中!但无论如何我提到了我的资源 ;) 它不是 Marashi 2.0 :D
猜你喜欢
  • 2017-10-23
  • 2012-07-28
  • 2013-02-23
  • 2023-03-19
  • 2014-03-22
  • 2017-09-12
  • 2011-02-04
  • 2020-11-06
  • 1970-01-01
相关资源
最近更新 更多