java - 当 p:poll 停止时传递对话 id 作为参数
问题描述
我正在使用 Primefaces 和 p:poll,因为我想在条件满足后轮询停止时导航到另一个页面。在两个页面上都使用了相同的对话 bean。(实际上有三个页面使用了这个bean)。
但是我不知道如何在轮询停止时将对话 ID 作为参数传递,如果有链接或按钮则传递的方式,因为 f:param 不能与 p:poll 一起使用。
任何帮助,将不胜感激。
提前致谢。
解决方案
我认为你有两个问题:
- 如何制作多页向导?
- 如何检查任务(搜索)是否完成?
如何制作多页向导?
我认为这不是您的主要问题,您已经找到了解决方案。这只是为了完整性。
如何检查任务(搜索)是否完成?
为此,您还获得了与此类似的解决方案。
但正如@Jasper_de_Vries 在评论中所说,websocket的性能比p:poll
.
所以这是我对第二个问题的解决方案:
演示 XHTML 文件:
<h:form>
<!-- must be in form when it has nested f:ajax's -->
<f:websocket channel="demo" scope="view">
<!-- renders the form and the 'someId' component -->
<!-- when receives 'complete' message -->
<f:ajax event="complete" render="@form :someId" />
</f:websocket>
<!-- display result here -->
</h:form>
<xy:whatever id="someId">
<!-- display result here -->
</xy:whatever>
还有你的豆子:
@Named
@ConversationScoped
public class Demo {
@Inject
private SomeService service;
@Inject @Push
private PushContext demo; // variable name must match the channel name
private Result result; // getter + setter
// conversation utilities, etc.
private void sendMessage() {
demo.send("complete"); // this is the whole magic
}
public void startLongTask() {
service.startLongTask(/* parameters */, result -> {
// this runs when the callback is accepted
this.result = result;
sendMessage();
});
}
}
一些服务:
@Stateless/@Stateful
public class SomeServiceService {
@Asynchronous
public void startLongTask(/* parameters*/, Consumer<Result> callback) {
// very long task ...
callback.accept(result);
}
}
基本上,当用户单击按钮时,就会启动一个长任务(例如搜索)。当服务完成时,它将调用回调并更新 UI。
这f:websocket
是 JSF 2.3 的一个特性。如果您不使用 JSF 2.3,请查看 Omnifaces Websocket o:websocket
。
推荐阅读
- visual-studio - Visual Studio 撤消删除存储
- c++ - 在一个 std::string 中多次匹配正则表达式
- node.js - 在 React 中授权管理员
- angular - Transloco translateService.translate 在 app.component.ts 中不起作用
- .net - 如何将 Nuget 包推送到 GitHub 包?
- java-stream - jenetics:在 stream() 之外设置 EvolutionStream 限制
- flutter - 我想全局定义一个变量,但它应该在本地初始化,并且其他类的数据应该相同
- r - How to get % of equality between all the combinations of columns in a data frame containing factors?
- c++ - 仅删除 stl 列表中的第一个遇到的元素
- vba - 在vba中将列与文本框值相乘