访问支持 bean 中执行属性传递的所有 ajax UIComponents?
Access all ajax UIComponents passed by execute attribute in backing bean?
以下代码是与 ajax 组件一起使用的简单形式:
<h:form id="loginform">
<h:inputText id="username">
<f:ajax event="blur" execute="loginform:username loginform:loginbutton" ... />
</h:inputText>
<h:inputText id="password">
<f:ajax event="blur" execute="loginform:password loginform:loginbutton" ... />
</h:inputText>
<h:commandButton id="loginbutton" value="login" action="#{indexBean.authentication()}" />
</h:form>
我知道执行属性是 space 分隔的组件 ID 列表,应该包含在 Ajax 请求中。
我可以使用 AjaxBehaviorEvent.getComponent()
方法访问支持 bean 的源组件,但是如何访问其余组件?
在 PartialViewContext#getExecuteIds()
之前可用。
FacesContext context = FacesContext.getCurrentInstance();
Collection<String> executeIds = context.getPartialViewContext().getExecuteIds();
// ...
然后您可以使用 UIViewRoot#findComponent()
通过客户端 ID 查找组件。
for (String executeId : executeIds) {
UIComponent component = context.getViewRoot().findComponent(executeId);
// ...
}
以下代码是与 ajax 组件一起使用的简单形式:
<h:form id="loginform">
<h:inputText id="username">
<f:ajax event="blur" execute="loginform:username loginform:loginbutton" ... />
</h:inputText>
<h:inputText id="password">
<f:ajax event="blur" execute="loginform:password loginform:loginbutton" ... />
</h:inputText>
<h:commandButton id="loginbutton" value="login" action="#{indexBean.authentication()}" />
</h:form>
我知道执行属性是 space 分隔的组件 ID 列表,应该包含在 Ajax 请求中。
我可以使用 AjaxBehaviorEvent.getComponent()
方法访问支持 bean 的源组件,但是如何访问其余组件?
在 PartialViewContext#getExecuteIds()
之前可用。
FacesContext context = FacesContext.getCurrentInstance();
Collection<String> executeIds = context.getPartialViewContext().getExecuteIds();
// ...
然后您可以使用 UIViewRoot#findComponent()
通过客户端 ID 查找组件。
for (String executeId : executeIds) {
UIComponent component = context.getViewRoot().findComponent(executeId);
// ...
}