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

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

问题描述

有没有办法让JSF Backing bean导致页面上组件的更新?我不希望使用具有update属性的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添加到

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

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

使用特定于PrimeFaces的API,使用 RequestContext#update() .

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

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

从PrimeFaces 6.2 RequestContext#update()起已弃用,请使用

From PrimeFaces 6.2 RequestContext#update() has been deprecated, use PrimeFaces::Ajax#update instead.

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

如果您碰巧使用了JSF实用程序库 OmniFaces ,请使用

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

Ajax.update("foo:bar");

无论采用哪种方式,请注意,这些客户端ID应当代表绝对的客户端ID,就像在视图端一样,这些客户端客户端的 not 前缀为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天全站免登陆