P:复合组件中的对话JS错误:未捕获类型错误:无法读取未定义的属性';显示'; [英] p:dialog in composite component JS error: Uncaught TypeError: Cannot read property 'show' of undefined
问题描述
我正在尝试创建一个复合组件以在我的JSF2.2页面中使用。以下是合成图:
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:cc="http://java.sun.com/jsf/composite">
<cc:interface componentType="searchUser">
<!-- Define component attributes here -->
<cc:attribute name="update" type="java.lang.String"
shortDescription="the component to update"/>
<cc:attribute name="widgetVar" type="java.lang.String"/>
</cc:interface>
<cc:implementation>
<p:dialog header="Search for User"
widgetVar="#{cc.widgetVar}"
modal="true"
id="searchDialog"
>
<p:panelGrid columns="2" id="searchPanel">
<p:outputLabel value="First Name: "
for="firstname"
/>
<p:inputText id="firstname" value="#{SearchBean.firstname}"/>
<p:outputLabel value="Last Name: "
for="lastname"
/>
<p:inputText id="lastname" value="#{SearchBean.lastname}"/>
<p:commandButton value="search"/>
<p:dataTable value="#{SearchBean.results}" var="user">
<p:column headerText="First Name">
#{user.firstName}
</p:column>
<p:column headerText="Last Name">
#{user.lastName}
</p:column>
<p:column headerText="E-Mail">
#{user.email}
</p:column>
</p:dataTable>
</p:panelGrid>
</p:dialog>
</cc:implementation>
我是这样使用它的:
<my:searchUser update="foo" id="searchDLG" widgetVar="sdgl"/>
<p:commandButton onclick="PF('sdgl').show();" type="button" value="search for user" />
当前My FacesComponent Java为空:
@FacesComponent("searchUser")
public class searchUser extends UIInput implements NamingContainer {
}
目标是创建一个我可以在多个位置使用的搜索表单/对话框。
我的问题是,在点击时,我得到错误:Uncaught TypeError: Cannot read property 'show' of undefined
。
如有任何关于我遗漏之处的建议,我将不胜感激。
推荐答案
这不是引用复合属性的正确方式。
<p:dialog widgetVar="#{cc.widgetVar}">
它基本上是引用支持组件本身的属性。
复合属性按#{cc.attrs}
映射可用。
<p:dialog widgetVar="#{cc.attrs.widgetVar}">
JS错误是因为实际的widgetVar
值为空,并且PF('sdgl')
返回undefined
,然后您盲目地尝试调用show()
函数。它基本上类似于Java中的NullPointerException
。
另请参阅:
与具体问题无关此组合还有两个其他问题:
支持组件未返回所需的组件系列
UINamingContainer.COMPONENT_FAMILY
。您可以通过从UINamingContainer
而不是UIInput
扩展,或者通过覆盖getFamily()
方法返回UINamingContainer.COMPONENT_FAMILY
来修复它。这不是复合组件的正确用途。根本没有单一的型号价值。也就是说,您没有与现有标准组件类似的
<my:searchUser value="...">
。而是使用包含或标记文件。另请参阅When to use <ui:include>, tag files, composite components and/or custom components?,否则,请重新处理组合,以便最终可以使用<my:searchUser value="#{bean.foundUser}">
。
这篇关于P:复合组件中的对话JS错误:未捕获类型错误:无法读取未定义的属性';显示';的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!