Jsf p:复合组件JS中的对话框错误:未捕获类型错误:无法读取属性';显示';未定义的
我试图创建一个复合组件,用于JSF2.2页面。以下是合成图:Jsf p:复合组件JS中的对话框错误:未捕获类型错误:无法读取属性';显示';未定义的,jsf,primefaces,dialog,typeerror,composite-component,Jsf,Primefaces,Dialog,Typeerror,Composite Component,我试图创建一个复合组件,用于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">
<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>
目标是创建一个搜索表单/对话框,我可以在多个位置使用它
我的问题是,单击时出现错误:uncaughttypeerror:无法读取未定义的属性“show”
如果您对我缺少的内容有任何建议,我们将不胜感激。这不是引用复合属性的正确方法
<p:dialog widgetVar="#{cc.widgetVar}">
导致JS错误的原因是实际的widgetVar
值为空,并且返回了PF('sdgl')
,然后盲目地尝试调用show()
函数。它基本上类似于Java中的NullPointerException
另见:
与具体问题无关,此组合还有两个其他问题:
<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>
UINamingContainer.component\u族的组件族
。您可以通过从UINamingContainer
扩展而不是UIInput
,或者通过重写getFamily()
方法返回UINamingContainer.COMPONENT\u FAMILY
来修复它
。而是使用include或tagfile。另请参见,重新编写组合,以便最终使用
这不是引用复合属性的正确方法
<p:dialog widgetVar="#{cc.widgetVar}">
导致JS错误的原因是实际的widgetVar
值为空,并且返回了PF('sdgl')
,然后盲目地尝试调用show()
函数。它基本上类似于Java中的NullPointerException
另见:
与具体问题无关,此组合还有两个其他问题:
<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>
UINamingContainer.component\u族的组件族
。您可以通过从UINamingContainer
扩展而不是UIInput
,或者通过重写getFamily()
方法返回UINamingContainer.COMPONENT\u FAMILY
来修复它
。而是使用include或tagfile。另请参见,重新编写组合,以便最终使用
好的,我更改了一些细节:1.)将命令按钮移动到复合组件,使其现在看起来像:
..
,在xhtml中,我现在有:
,结果是命令按钮没有显示。Thaught将按钮直接放在组件中会更有意义吗?在最初的问题所在的位置解决问题?抱歉,我尝试过,但它没有解决问题,我的猜测是,它与我的评论中的问题有关。我不确定移动按钮与修复复合属性引用有何关系。您是说在将{cc.widgetVar}
修复为{cc.attrs.widgetVar}
后,仍然会得到未捕获的类型错误:无法读取未定义的属性'show'。是的,错误消息保持不变。所以我猜测组件没有正确添加到页面/DOM,这就是为什么如果我将命令按钮移动到组件,它根本不显示。好的,我更改了一些细节:1)将命令按钮移动到复合组件,使其现在看起来像:…
,在xhtml中,我现在有:
,结果是命令按钮没有显示。Thaught将按钮直接放在组件中会更有意义吗?在最初的问题所在的位置解决问题?抱歉,我尝试过,但它没有解决问题,我的猜测是,它与我的评论中的问题有关。我不确定移动按钮与修复复合属性引用有何关系。您是说在将{cc.widgetVar}
修复为{cc.attrs.widgetVar}
后,仍然会得到未捕获的类型错误:无法读取未定义的属性'show'。是的,错误消息保持不变。因此,我的猜测是组件没有正确地添加到页面/DOM中,这就是为什么如果我将命令按钮移动到组件中,它根本不会显示。