我可以从 JSF 支持 bean 方法更新 JSF 组件吗? [英] Can I update a JSF component from a JSF backing bean method?

查看:24
本文介绍了我可以从 JSF 支持 bean 方法更新 JSF 组件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让 JSF Backing bean 导致页面上的组件更新?我不打算使用具有更新属性的 ajax 组件来更新页面上的组件.我需要从 JSF 支持 bean 方法中触发更新.请注意,页面上的更新可能会在此方法完成之后或完成之前发生.我正在使用 PrimeFaces,如果有可以通过使用 PrimeFaces 获得的解决方案.

Is there a way to have a JSF Backing bean cause an update of a component on the page? I am not looking to use an ajax component with update attribute to update a component on the page. I need to trigger an update from within a JSF backing bean method. Note the update on the page can happen after this method completes or prior to its completion. I am using PrimeFaces, if there is a solution that can be had from using PrimeFaces.

推荐答案

使用标准 JSF API,将客户端 ID 添加到 PartialViewContext#getRenderIds().

Using standard JSF API, add the client ID to PartialViewContext#getRenderIds().

FacesContext.getCurrentInstance().getPartialViewContext().getRenderIds().add("foo:bar");

使用 PrimeFaces 特定 API,使用 PrimeFaces.Ajax#update().

Using PrimeFaces specific API, use PrimeFaces.Ajax#update().

PrimeFaces.current().ajax().update("foo:bar");

或者,如果您还没有使用 PrimeFaces 6.2+,请使用 RequestContext#update().

Or if you're not on PrimeFaces 6.2+ yet, use RequestContext#update().

RequestContext.getCurrentInstance().update("foo:bar");

如果您碰巧使用 JSF 实用程序库 OmniFaces,请使用 Ajax#update().

If you happen to use JSF utility library OmniFaces, use Ajax#update().

Ajax.update("foo:bar");

无论如何,请注意,这些客户端 ID 应表示绝对客户端 ID,NamingContainer 分隔符为前缀,就像您在视图端所做的那样

Regardless of the way, note that those client IDs should represent absolute client IDs which are not prefixed with the NamingContainer separator character like as you would do from the view side on.

这篇关于我可以从 JSF 支持 bean 方法更新 JSF 组件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆