如何以编程方式对支持 bean 中的特定组件进行 ajax 更新

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16101392/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 10:59:41  来源:igfitidea点击:

How to programmatically ajax-update specific component in backing bean

ajaxjsfprimefacesupdates

提问by Venkat Maridu

Is there a way to ajax-update a specific component such as a <h:form>in backing bean?

有没有办法 ajax 更新特定组件,例如<h:form>支持 bean?

I tried the following using RequestContext#execute(),

我尝试了以下使用RequestContext#execute()

RequestContext context = RequestContext.getCurrentInstance();
context.execute("monitorVehicleForm.update()");

however that didn't seem to have any effect.

然而,这似乎没有任何效果。

回答by BalusC

The RequestContext#execute()only executes arbitrary JavaScript code which is been passed-in as argument. It does not ajax-update the client representation of the components.

RequestContext#execute()仅执行其中被传入作为参数任意JavaScript代码。它不会对组件的客户端表示进行 ajax 更新。

You need RequestContext#update()instead wherein you just pass the client ID of the to-be-updated component.

RequestContext#update()相反,您需要在其中传递要更新的组件的客户端 ID。

context.update("monitorVehicleForm");

This has exactly the same effect as <p:commandXxx ... update="monitorVehicleForm">. This works provided you've a

这与<p:commandXxx ... update="monitorVehicleForm">. 只要你有一个

<h:form id="monitorVehicleForm">

without any NamingContainerparent and thus have a

没有任何NamingContainer父母,因此有一个

<form id="monitorVehicleForm" name="monitorVehicleForm" ...> 

in the generated HTML.

在生成的 HTML 中。

See also:

也可以看看: