1

我使用 DataTable - 从主要面孔中选择行来显示用户列表,当我运行该页面时,我遇到了这个错误

Cannot find component with identifier ":form:display" referenced from "j_idt24:people:0:selectButton".

页面代码

<!--    the part is very important 
if we did not put  <ui:composition> will will get a very ugly UI
-->
    <ui:composition>
    <h:head>
        <title>Contacts</title>
    </h:head>       
<!--    the part is very important --> 

    <body>
        <h:form>

          <p:growl id="msgs" showDetail="true" />  

          <p:dataTable id="people" var="person" value="#{personBean.users}">  

        <p:column headerText="ID" style="width:24%">  
            <h:outputText value="#{person.id}" />  
        </p:column>  

        <p:column headerText="Name" style="width:24%">  
            <h:outputText value="#{person.name}" />  
        </p:column>  

        <p:column headerText="Sex" style="width:24%">  
            <h:outputText value="#{person.sex}" />  
        </p:column>  

        <p:column headerText="Email" style="width:24%">  
            <h:outputText value="#{person.email}" />  
        </p:column>  

        <p:column style="width:4%">  
                <p:commandButton id="selectButton"  oncomplete="personDialog.show()" icon="ui-icon-search" title="View"  update=":form:display" >  
                    <f:setPropertyActionListener value="#{person}" target="#{personBean.selectedPerson}" />  
            </p:commandButton>  
        </p:column>  

    </p:dataTable>  

    <p:dialog header="Person Detail" widgetVar="personDialog" resizable="false" id="perDlg"  
                showEffect="fade" hideEffect="explode" modal="true">  

        <h:panelGrid id="display" columns="2" cellpadding="4" style="margin:0 auto;">  



            <h:outputText value="Name:" />  
            <h:outputText value="#{personBean.selectedPerson.name}" style="font-weight:bold"/>  

            <h:outputText value="Sex" />  
            <h:outputText value="#{personBean.selectedPerson.sex}" style="font-weight:bold"/>  


            <h:outputText value="Email" />  
            <h:outputText value="#{personBean.selectedPerson.email}" style="font-weight:bold"/>  



        </h:panelGrid>  

    </p:dialog>  

        </h:form>
    </body>
        </ui:composition>
</html>

我的代码有什么问题?

4

2 回答 2

4

您在按钮中使用了 'update=":form:display"',但您的表单没有 id,因此 ':form' 不正确。如果你给你的表单一个id,例如myForm。然后你可以使用 :myForm:display

基本上你需要看看 Namingcontainers 你需要了解引用元素(参见例如:JSF2/PrimeFaces 中的命名容器

于 2013-06-05T16:38:03.280 回答
2

您必须在 h:form 中设置 id="form"。附加到按钮 id 的错误消息中随机生成的 id 是表单的生成 id。如果您将其设置为您使用的 id 将起作用。另一种方法是在按钮更新中使用相对 id。

于 2013-06-05T16:33:31.707 回答