我使用的是Primefaces和p:poll,因为在条件成立后轮询停止时我想导航到另一页。在两个页面上,都使用相同的对话bean。 (实际上,有三个页面使用此bean)。
但是我不知道在轮询停止时如何将对话ID作为参数传递,如果有链接或按钮,该传递的方式将作为参数传递,因为f:param不能与p:poll一起使用。
任何帮助将不胜感激。
谢谢。
答案 0 :(得分:1)
我认为您遇到两个问题:
我认为这不是您的主要问题,并且您已经找到了解决方案。这只是为了完善。
您可以使用flow或conversation(我会使用它)。
为此,您还获得了类似于this的解决方案。
但是正如@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();
});
}
}
SomeService:
@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
。