I think you got two problems:
- How to make a multi-page wizard?
- How to check if a task (search) is finished?
How to make a multi-page wizard?
I think that is not your main problem and you already got a solution. This is just for the sake of completness.
You can either use a flow or a conversation (I would use this).
How to check if a task (search) is finished?
For this you also got a solution that is similar to this.
But as @Jasper_de_Vries said in the comments a websocket has a way better performance than a p:poll
.
So here's my solution for the second problem:
Demo XHTML file:
<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>
And your bean:
@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);
}
}
Basically when the user clicks the button a long task (e.g. a search) is started. When the service completes it will invoke the callback and the UI is updated.
The f:websocket
is a feature of JSF 2.3. If you aren't using JSF 2.3 look at the Omnifaces Websocket o:websocket
.