java 找不到引用自标识符“:form:display”的组件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16945025/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot find component with identifier ":form:display" referenced from
提问by Mohammed Subhi Sheikh Quroush
I used DataTable - Row Selection from prime faces to display list of users and when I run the page I faced this error
我使用 DataTable - Row Selection from primefaces 来显示用户列表,当我运行页面时,我遇到了这个错误
Cannot find component with identifier ":form:display" referenced from "j_idt24:people:0:selectButton".
code of page
页面代码
<!-- 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>
what is the problem with my code ?
我的代码有什么问题?
回答by zargarf
You are using 'update=":form:display"' in your button, but your form does not have an id so ':form' is incorrect. If you give your form an id, e.g. myForm. Then you could use :myForm:display
您在按钮中使用了 'update=":form:display"',但您的表单没有 id,因此 ':form' 不正确。如果你给你的表单一个 id,例如 myForm。然后你可以使用 :myForm:display
Basically you need to take a look at Namingcontainers which you'll need to understand to reference elements(see for example: Naming Container in JSF2/PrimeFaces)
基本上,您需要查看 Namingcontainers,您需要了解它以引用元素(参见例如:JSF2/PrimeFaces 中的 Naming Container)
回答by user1983983
You have to set id="form" at the h:form. The randomly generated id in the error message which is prepended to the buttons id, is the generated id of the form. If you set it to form the id you used will work. An alternative would be to use a relative id in the update of the button.
您必须在 h:form 中设置 id="form"。错误消息中随机生成的 id 是附加到按钮 id 的,是表单的生成 id。如果您将其设置为形成您使用的 id 将起作用。另一种方法是在按钮的更新中使用相对 id。