我正在尝试在 JSF 2 中实现一个复合组件,它将支持“更改”ajax 事件。 CC 是:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.prime.com.tr/ui"
xmlns:composite="http://java.sun.com/jsf/composite">
<!-- INTERFACE -->
<composite:interface name="inputText">
<composite:attribute name="label" />
<composite:attribute name="value" />
<composite:attribute name="disabled" default="false" />
<composite:attribute name="required" default="false" />
<composite:attribute name="rendered" default="true" />
<composite:clientBehavior name="change" event="change"
targets="#{cc.clientId}:input" />
</composite:interface>
<!-- IMPLEMENTATION -->
<composite:implementation>
<h:panelGroup id="#{cc.clientId}" rendered="#{cc.attrs.rendered}">
<h:outputLabel value="#{cc.attrs.label}" for="input" />
<h:inputText id="input" label="#{cc.attrs.label}"
value="#{cc.attrs.value}" disabled="#{cc.attrs.disabled}"
required="#{cc.attrs.required}" />
<h:message for="input" />
</h:panelGroup>
</composite:implementation>
</html>
现在,我尝试以以下形式使用它:
<h:form id="form">
<input:inputText value="#{bean.value}" label="d1" id="d1">
<f:ajax event="change" update="@this,d2,d3" />
</input:inputText>
<h:inputText value="#{bean.value}" id="d2">
<f:ajax event="change" update="@this,d1,d3" />
</h:inputText>
<h:outputText id="d3" value="#{bean.value}" />
</h:form>
据我了解,如果我更改d1,d2和d3应该显示d1的值,如果我更改d2,d1和d3也应该相应更改。
问题是,当我更改 d2 中的值时,它仅反射(reflect)在 d3 中,而 d1 保持空白,而当我更改 d2 时,d1 和 d2 保持空白。
我正在使用 Mojarra 2.0.2(我无法在 Google App Engine 上制作 2.0.3,这是我的 AS)。我是否错过了构建复合组件的方式中的某些内容?或者是 Mojarra 2.0.2 中的一个错误?
最佳答案
这个:
<h:panelGroup id="#{cc.clientId}"
不正确。 #{cc.clientId}
是组件的 ID,它是该 panelGroup 的父组件。将它们设置为具有相同的 ID 是不正确的。给它一个像“myComponentPanel
”这样的id,它将具有“#{cc.clientId}:myComponentPanel
”的绝对id(当放置在组件树中时)。
我怀疑如果你纠正这个问题,你的ajax行为就会起作用。
关于java - JSF 2 复合组件不使用 f :ajax 更新值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5526327/