问题描述
我在jsf页面中有一个自定义javascript Ajax调用.我在过滤器中捕获并处理XMLHttpRequest的查询字符串.过滤器将记录添加到模型中的表.现在,我希望没有整个页面刷新的jsf页面在其中一个组件(Primefaces数据表)中反映更新的模型.
I have a custom javascript Ajax call in my jsf page. I capture and process the query string of the XMLHttpRequest in a filter. The filter adds a record to a table in the model.Now I want the jsf page, without full page refresh, to reflect the updated model in one of the components (a Primefaces data table).
我想我需要的是自定义xmlHttpResponse ...
I guess what I need is a custom xmlHttpResponse...
谁能告诉我该怎么做?我担心这可能很复杂,但是我别无选择,只能使用自定义的javascript ...
Can anyone tell me how to do this? I'm scared it might be complicated, but I have no choice but to use the custom javascript...
推荐答案
The PrimeFaces <p:remoteCommand>
is designed for this purpose.
这是针对您的特定案例的基本启动示例:
Here's a basic kickoff example for your particular case:
<h:form>
<p:remoteCommand name="updateTable" action="#{bean.updateTable}"
process="@this" update="table" />
...
<p:dataTable id="table">...</p:dataTable>
</h:form>
它将生成一个JS函数updateTable()
,该函数将调用#{bean.updateTable}
方法并使用(相对)客户端ID table
更新组件.您只需要在JavaScript上下文中调用函数updateTable()
.
It generates a JS function updateTable()
which will invoke the #{bean.updateTable}
method and update the component with (relative) client ID table
. You just have to call the function updateTable()
in JavaScript context.
updateTable();
如果需要,您甚至可以传递请求参数,它必须作为JS对象发送:
You can even pass request parameters if necessary, it has to be sent as JS object:
updateTable({ name1: "value1", name2: "value2 });
无需摆弄自制的ajax请求并保持JSF状态同步.
No need to fiddle with homebrewed ajax requests and keeping the JSF state in sync.
这篇关于自定义javascript Ajax调用后刷新JSF组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!