ajax - 访问由支持 bean 中的执行属性传递的所有 ajax UIComponent?

标签 ajax jsf jsf-2

以下代码是与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/

相关文章:

javascript - 在 ASP.NET MVC 中使用 ajax 使用 CRUD 操作时,DataTable 插件不起作用

jsf - 一个输入的多个验证器

java - CANNOT_FIND_FACELET_TAGLIB 对于 xmlns :jsf ="http://xmlns.jcp.org/jsf"

html - 从 Bootstrap 主题应用样式

php - 想要在单击 div 时调用 PHP 页面?

javascript - 使用 AJAX 加载的 iframe 代码未加载

Javascript - 无法解析通过 PHP 发送的 JSON 或字符串

java - 应用程序错误地创建了多个 CDI-Bean

spring - 添加Spring安全标签库

java - 使用 Primefaces 在文件系统上上传文件