java 如何在 JSF 2.0 中通过 AJAX 强制刷新数据表?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3152184/
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
How to force refresh of datatable via AJAX in JSF 2.0?
提问by Brian Knoblauch
I've got datatable, which is pulling information from a database. I've added a button to the form that I want to use to force the table (id of "table") to refresh, however I'm not sure how to do it. What I have now is:
我有数据表,它从数据库中提取信息。我在表单中添加了一个按钮,我想用它来强制刷新表(“表”的 ID),但是我不知道该怎么做。我现在拥有的是:
<h:commandButton value="Refresh">
<f:ajax render="table"/>
</h:commandButton>
My goal was to have the table component be forced to render when the button is clicked. However, it appears that either the click is being ignored, or it's returning cached data, rather than actually going out and calling my database code again.
我的目标是在单击按钮时强制呈现表格组件。但是,似乎单击被忽略,或者它返回缓存的数据,而不是实际出去并再次调用我的数据库代码。
What am I doing wrong?
我究竟做错了什么?
采纳答案by Brian Knoblauch
Ugh. It's actually working, just incredibly painfully slow. We switched database servers recently, and a query that took less than a second on the old one just happens to take 20+ seconds on the new one. I was just timing out while watching it. Sigh.
啊。它实际上是有效的,只是慢得令人难以置信。我们最近更换了数据库服务器,一个查询在旧的上用了不到一秒,而在新的上用了 20 多秒。我只是在看的时候超时。叹。
As a side note, as soon as I figured that out, I tested both with and without an action. Works both ways (with the getter doing the lookup).
作为旁注,一旦我想通了,我就在有和没有动作的情况下进行了测试。双向工作(使用吸气剂进行查找)。
回答by Ingo Fischer
You have to specify an action in your commandButton which calls a bean and refreshes the data displayed in the table (currently the button does nothing). I'm not a Pro, but i think it should look like this:
您必须在 commandButton 中指定一个操作,该操作调用 bean 并刷新表中显示的数据(当前该按钮不执行任何操作)。我不是专业人士,但我认为它应该是这样的:
<h:commandButton value="Refresh" action="#{myBean.refreshData}">
<f:ajax render="table"/>
</h:commandButton>

