以下代码是与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>
据我所知,execute 属性是一个以空格分隔的 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 - 访问由支持 bean 中的执行属性传递的所有 ajax UIComponent?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28853343/