0

我有一个 JSF 模板和几个模板客户端。当我添加动态 primefaces 菜单栏时,出现错误消息,即存在重复 ID 错误。我手动检查,我提供的 id 中没有重复项。当我删除 p:menubar 时,错误就解决了。

SEVERE: JSF1007: Duplicate component ID j_id2 found in view.
SEVERE: +id: j_id1
 type: javax.faces.component.UIViewRoot@197b245
  +id: javax_faces_location_HEAD
   type: com.sun.faces.component.ComponentResourceContainer@15e344b
    +id: j_idt6
     type: javax.faces.component.UIOutput@5f7a1
    +id: j_id2  <===============
     type: javax.faces.component.UIOutput@1bb6941
    +id: j_id3
     type: javax.faces.component.UIOutput@fb2b4a
    +id: j_id4
     type: javax.faces.component.UIOutput@1d72379
    +id: j_id5
     type: javax.faces.component.UIOutput@159ef51
    +id: j_id6
     type: javax.faces.component.UIOutput@16eaf88
  +id: j_idt2
   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_idt3
   type: <html xmlns="http://www.w3.org/1999/xhtml">
    <!--Author : Dr. M H B Ariyaratne, MO(Health Information), buddhika.ari@gmail.com-->

  +id: j_idt4
   type: javax.faces.component.UIOutput@13e40a4
    +id: j_idt5
     type: 
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>

    +id: j_idt7
     type: 
        <title>#{labels.topic}</title>

  +id: j_idt8
   type: javax.faces.component.UIOutput@1c46b0a
    +id: j_idt9
     type: org.primefaces.component.growl.Growl@4f6181
    +id: pStaff
     type: org.primefaces.component.panel.Panel@18a95c1
      +id: pgM
       type: javax.faces.component.html.HtmlPanelGrid@16de90f
        +id: j_idt10
         type: javax.faces.component.html.HtmlPanelGroup@e004a0
          +id: j_idt11
           type: javax.faces.component.html.HtmlForm@14fde45
            +id: j_idt12
             type: javax.faces.component.html.HtmlPanelGroup@8985b5
              +id: j_idt13
               type: org.primefaces.component.menubar.Menubar@a967cb
                +id: j_id2  <===============
                 type: org.primefaces.component.menuitem.MenuItem@1afb24a
                +id: j_id3
                 type: org.primefaces.component.submenu.Submenu@1e22365
                  +id: j_id4
                   type: org.primefaces.component.menuitem.MenuItem@181ddad
                  +id: j_id5
                   type: org.primefaces.component.menuitem.MenuItem@100bceb
                  +id: j_id6
                   type: org.primefaces.component.menuitem.MenuItem@173016f
                  +id: j_id7
                   type: org.primefaces.component.menuitem.MenuItem@16332a4
                  +id: j_id8
                   type: org.primefaces.component.menuitem.MenuItem@191e61d
                  +id: j_id9
                   type: org.primefaces.component.menuitem.MenuItem@19aa7db
                  +id: j_id10
                   type: org.primefaces.component.menuitem.MenuItem@82593c
                  +id: j_id11
                   type: org.primefaces.component.menuitem.MenuItem@1b07eb6
                +id: j_id12
                 type: org.primefaces.component.submenu.Submenu@4ee9d9
                  +id: j_id13
                   type: org.primefaces.component.menuitem.MenuItem@dae23d
                  +id: j_id14
                   type: org.primefaces.component.menuitem.MenuItem@3b2eed
                  +id: j_id15
                   type: org.primefaces.component.menuitem.MenuItem@185f8e9
                  +id: j_id16
                   type: org.primefaces.component.menuitem.MenuItem@98a265
                  +id: j_id17
                   type: org.primefaces.component.menuitem.MenuItem@cdbf40
                  +id: j_id18
                   type: org.primefaces.component.menuitem.MenuItem@1c71499
                  +id: j_id19
                   type: org.primefaces.component.menuitem.MenuItem@119832a
                  +id: j_id20
                   type: org.primefaces.component.menuitem.MenuItem@1f25dd7
                  +id: j_id21
                   type: org.primefaces.component.menuitem.MenuItem@eed568
                +id: j_id22
                 type: org.primefaces.component.submenu.Submenu@1fcb0c2
                  +id: j_id23
                   type: org.primefaces.component.menuitem.MenuItem@b8c8f7
                  +id: j_id24
                   type: org.primefaces.component.menuitem.MenuItem@19205d7
                +id: j_id25
                 type: org.primefaces.component.submenu.Submenu@1bd84ce
                  +id: j_id26
                   type: org.primefaces.component.menuitem.MenuItem@15a29b2
                  +id: j_id27
                   type: org.primefaces.component.menuitem.MenuItem@6766d6
        +id: j_idt14
         type: javax.faces.component.html.HtmlPanelGroup@1dd6bd9
          +id: j_idt15
           type: javax.faces.component.html.HtmlPanelGroup@1d3934a
            +id: form
             type: javax.faces.component.html.HtmlForm@16ae971
              +id: growl
               type: org.primefaces.component.growl.Growl@40dee
              +id: j_idt16
               type: javax.faces.component.html.HtmlCommandButton@2eb374
              +id: j_idt17
               type: org.primefaces.component.panel.Panel@78bf2
                +id: j_idt18
                 type: org.primefaces.component.panelgrid.PanelGrid@174cb3e
                  +id: j_idt19
                   type: org.primefaces.component.panelgrid.PanelGrid@cb6dd6
                    +id: pDetails
                     type: org.primefaces.component.panel.Panel@19819bb
                      +id: tvPs
                       type: org.primefaces.component.tabview.TabView@c15e73
                        +id: tabNewOpd
                         type: org.primefaces.component.tabview.Tab@11ff44f
                          +id: j_idt20
                           type: 
                                                New Opd Pt

                          +id: j_idt21
                           type: org.primefaces.component.calendar.Calendar@e08ff0
                        +id: tabSearchOpd
                         type: org.primefaces.component.tabview.Tab@109e252
                          +id: j_idt22
                           type: 
                                                Search Opd Pt

                        +id: tabBht
                         type: org.primefaces.component.tabview.Tab@1e995d3
                          +id: j_idt23
                           type: 
                                                BHT

                        +id: tabCompany
                         type: org.primefaces.component.tabview.Tab@6b6109
                          +id: j_idt24
                           type: 
                                                New Company

                      +id: j_idt25
                       type: javax.faces.component.html.HtmlPanelGrid@1afce81
                        +id: j_idt26
                         type: javax.faces.component.html.HtmlOutputText@11e9df9
                        +id: acPt
                         type: org.primefaces.component.autocomplete.AutoComplete@1154808
                        +id: txtPtName
                         type: javax.faces.component.html.HtmlOutputText@2c2dc7
                        +id: j_idt27
                         type: javax.faces.component.html.HtmlOutputText@71a488
                        +id: txtPtAdd
                         type: javax.faces.component.html.HtmlInputText@e8e006
                        +id: j_idt28
                         type: javax.faces.component.html.HtmlOutputText@cbb18f
                        +id: txtPtPhone
                         type: javax.faces.component.html.HtmlInputText@f651da
                    +id: j_idt29
                     type: org.primefaces.component.panel.Panel@177fa2d
                      +id: j_idt30
                       type: javax.faces.component.html.HtmlSelectOneListbox@1c9a536
                        +id: j_idt31
                         type: javax.faces.component.UISelectItems@17d8e95
                      +id: j_idt32
                       type: javax.faces.component.html.HtmlCommandButton@1bde17
                    +id: j_idt33
                     type: org.primefaces.component.panel.Panel@191e94c
                      +id: j_idt34
                       type: javax.faces.component.html.HtmlDataTable@6ba042
                        +id: j_idt35
                         type: javax.faces.component.UIColumn@1e685b0
                          +id: j_idt36
                           type: #{b.item.name}
                        +id: j_idt37
                         type: javax.faces.component.UIColumn@15314f2
                          +id: j_idt38
                           type: #{b.item.total}
                    +id: j_idt39
                     type: javax.faces.component.html.HtmlOutputText@1845b1f
                    +id: txtTotal
                     type: javax.faces.component.html.HtmlOutputText@7a5621
                  +id: j_idt40
                   type: org.primefaces.component.panel.Panel@1aca028
                    +id: j_idt41
                     type: org.primefaces.component.commandbutton.CommandButton@46dc65
                      +id: j_idt42
                       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">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui">
    <!--Author : Dr. M H B Ariyaratne, MO(Health Information), buddhika.ari@gmail.com-->
    <h:head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <h:outputStylesheet library="css" name="maincss.css" />
        <title>#{labels.topic}</title>
    </h:head>
    <h:body >
        <p:growl id="publicGrowl" autoUpdate="true"/>
        <p:panel id="pStaff" header="#{labels.topic}" >
            <h:panelGrid id="pgM" columns="1" >
                <h:panelGroup >
                    <h:form>
                        <h:panelGroup >
                            <p:menubar model="#{menuController.model}" ></p:menubar>
                        </h:panelGroup>
                    </h:form>
                </h:panelGroup>
                <h:panelGroup rendered ="#{sessionController.logged}" >
                    <ui:insert name="content"   >
                        Use Menu to Navigate
                    </ui:insert>
                </h:panelGroup>
                <h:panelGroup rendered ="#{!sessionController.logged}" >
                    <ui:insert name="login"   >
                        <p:panel header="Please login" id="loginbox">
                            <h:panelGrid columns="2" >
                                <h:panelGroup >
                                    <h:graphicImage  library="image" name="lock.png" />
                                </h:panelGroup>
                                <h:panelGroup >
                                    <h:form id="formLogin">
                                        <h:panelGrid columns="2">
                                            <h:outputLabel value="Username" ></h:outputLabel>
                                            <h:inputText autocomplete="off"  value="#{sessionController.userName}" ></h:inputText>
                                            <h:outputLabel value="Password" ></h:outputLabel>
                                            <h:inputSecret value="#{sessionController.passord }" ></h:inputSecret>
                                            <h:outputLabel value="Password" ></h:outputLabel>
                                            <h:commandButton value="Login" action="#{sessionController.loginAction()}" ></h:commandButton>
                                        </h:panelGrid>
                                    </h:form>
                                </h:panelGroup>
                            </h:panelGrid>
                        </p:panel>
                    </ui:insert>
                </h:panelGroup>
                <h:panelGroup >
                    <h:form>
                        <h:outputLabel  value="You are logged as #{sessionController.loggedUser.webUserPerson.name}&nbsp;(#{sessionController.loggedUser.role.name})."  rendered ="#{sessionController.logged}" ></h:outputLabel><h:commandLink value="Logout" action="#{sessionController.logout}"  rendered ="#{sessionController.logged}" ></h:commandLink>
                        <h:outputLabel  value="Please login to continue."  rendered ="#{!sessionController.logged}" ></h:outputLabel>
                    </h:form>
                    Copyright © 2013 | All Rights Reserved  
                </h:panelGroup>
            </h:panelGrid>
        </p:panel>
    </h:body>
</html>

JSF 模板客户端

<?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:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core">
    <h:body>
        <ui:composition  template="./resources/template/staff_template.xhtml">
            <ui:define name="content">
                <h:panelGroup >
                    <h:form id="form">
                        <p:growl id="growl" showDetail="true" />  
                        <h:commandButton value="Create Pt" action="#{patientController.createRandomPatient('Budi')}" />
                        <p:panel header="Lab Bill" >
                            <p:panelGrid columns="2" >
                                <p:panelGrid columns="1" >
                                    <p:panel id="pDetails" header="Patient Details" >
                                        <p:tabView id="tvPs"  >
                                            <p:ajax event="tabChange" listener="#{labBillController.onTabChange}" update=":form:growl"/>
                                            <p:tab id="tabNewOpd" title="New OPD Patient" >
                                                New Opd Pt
                                            </p:tab>
                                            <p:tab id="tabSearchOpd" title="New OPD Patient">
                                                Search Opd Pt
                                            </p:tab>
                                            <p:tab id="tabBht" title="BHT">
                                                BHT
                                            </p:tab>
                                            <p:tab id="tabCompany" title="Company">
                                                New Company
                                            </p:tab>
                                        </p:tabView>
                                        <h:panelGrid columns="2">
                                            <h:outputText value="Name"/>
                                            <p:autoComplete value="#{labBillController.currentPatient}" id="acPt" completeMethod="#{patientController.completePatient}"  
                                                            var="p" itemLabel="#{p.person.name}" itemValue="#{p}"  >
                                                <f:ajax event="select" execute="acPt" render="txtPtName txtPtAdd txtPtPhone" />
                                            </p:autoComplete>  
                                            <h:outputText id="txtPtName" value="#{labBillController.currentPatient.person.name}"/>
                                            <h:outputText  value="Address"/>
                                            <h:inputText id="txtPtAdd" value="#{labBillController.currentPatient.person.address}"/>
                                            <h:outputText value="Phone"/>
                                            <h:inputText id="txtPtPhone" value="#{labBillController.currentPatient.person.phone}"/>
                                        </h:panelGrid>
                                    </p:panel>
                                    <p:panel header="Investigation Detail" >
                                        <h:selectOneListbox value="#{labBillController.currentBillItem.item}" >
                                            <f:selectItems  value="#{investigationController.items}"  var="myItem" itemValue="#{myItem}" itemLabel="#{myItem.name}"  />
                                        </h:selectOneListbox>
                                        <h:commandButton value="AddItem" action="#{labBillController.addToBill()}" />
                                    </p:panel>
                                    <p:panel header="Request Details" >
                                        <h:dataTable value="#{labBillController.billItems}" var="b">
                                            <h:column >#{b.item.name}</h:column>
                                            <h:column >#{b.item.total}</h:column>
                                        </h:dataTable>
                                    </p:panel>
                                    <h:outputText value="Total"/>
                                    <h:outputText value="#{labBillController.current.total}" id="txtTotal"/>
                                </p:panelGrid>
                                <p:panel header="Bill Details" >
                                    <p:commandButton value="Settle" actionListener="#{labBillController.settleBill}" ajax="false" >
                                        <!--<p:printer target="pDetails"  />-->
                                    </p:commandButton>
                                </p:panel>
                            </p:panelGrid>
                        </p:panel>
                    </h:form>
                </h:panelGroup>
            </ui:define>
        </ui:composition>
    </h:body>
</html>
4

1 回答 1

0

我完全重写了代码,后记没有错误。我认为,虽然我无法追踪任何重复的 Id,但肯定有一个。这次也出现了同样的错误,我发现有自己引入的重复。如果有人遇到同样的错误,我认为它很有可能是由手动插入重复 ID 中的重复引起的。

于 2013-06-17T23:10:45.150 回答