How to programmatically ajax-update specific component in backing bean

拜拜、爱过 提交于 2019-12-09 05:50:48

问题


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

I tried the following using RequestContext#execute(),

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

however that didn't seem to have any effect.


回答1:


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.

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

context.update("monitorVehicleForm");

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

<h:form id="monitorVehicleForm">

without any NamingContainer parent and thus have a

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

in the generated HTML.

See also:

  • How to find out client ID of component for ajax update/render? Cannot find component with expression "foo" referenced from "bar"


来源:https://stackoverflow.com/questions/16101392/how-to-programmatically-ajax-update-specific-component-in-backing-bean

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!