【发布时间】:2014-08-25 21:42:01
【问题描述】:
我正在使用 PrimeFaces 5 编写一个应用程序,目前我正在编写一个包含几个 AutoComplete 元素的屏幕,其想法是一个自动完成的值会影响第二个自动完成中可用的选择。
我试图让它工作的方式是,当它填充第一个自动完成时,会触发一个 Ajax 事件以使用该值更新支持 bean,因此当调用第二个自动完成时,它具有该值从第一个自动完成准备开启。
这是页面:
<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://xmlns.jcp.org/jsf/passthrough"
xmlns:pf="http://primefaces.org/ui">
<pf:panel id="header" header="Details" style="margin-bottom:20px">
<h:panelGrid columns="3" style="margin-bottom:10px;border-style:solid;border-width:0.1em;width:100%" cellpadding="5">
<pf:outputLabel id="input1Label" for="input1" value="Specify Input 1" />
<pf:autoComplete id="input1" value="#{bean.input1}" completeMethod="#{bean.completeInput1}"
var="input1" itemLabel="#{input1}" itemValue="#{input1}" >
<pf:ajax event="itemSelect" listener="#{bean.input1ItemSelect}"/>
</pf:autoComplete>
<pf:message id="input1Msg" for="input1"/>
<pf:outputLabel id="input2Label" for="input2" value="Input 2?" />
<pf:autoComplete id="input2" value="#{bean.input2}" completeMethod="#{bean.completeInput2}"
var="input2" itemLabel="#{input2}" itemValue="#{input2}" />
<pf:message id="input2Msg" for="input2"/>
</h:panelGrid>
</pf:panel>
</ui:composition>
但是,当在 input1 中选择一个值时,我收到此错误:
无法访问,标识符“bean”解析为 null:javax.el.PropertyNotFoundException:目标无法访问,标识符“bean”解析为 null
接下来要指出的是,这个组合包含在父组合中,并且“bean”作为参数以下列方式传入:
<c:forEach items="#{parentBean.blockNames}" var="blockName" varStatus="loop">
<f:subview id="block_subview_#{loop.index}">
<ui:include src="#{blockName}">
<ui:param name="bean" value="#{parentBean.blockBeans[loop.index]}"/>
</ui:include>
</f:subview>
</c:forEach>
我能够确定的是,如果我将 pf:ajax 标记中的引用“bean”更改为命名 bean,它能够解析 bean 引用并尝试调用侦听器方法。因此,出于某种原因,pf:ajax 标记似乎无法处理“bean”引用,因为它不是实际 bean 的名称,而是从父级传入的 bean 参数的名称。然而,所有其他标签都可以完美地解析这里的“bean”。
有没有办法解决这个问题?
编辑:
将 pf:ajax 更改为 f:ajax 似乎使错误消失,至少随后调用了正确的侦听器方法。我宁愿不使用这种方法,但也许这些信息很有用。
【问题讨论】:
标签: jsf jsf-2 primefaces