Reputation: 1887
I was wondering if you could render or update a page while you still inside a method; here is an example: the .xhtml file:
<h:form id="form">
<h:commandButton value="change" actionListener="#{bean.changeText}">
<f:ajax render="out" />
</h:commandButton>
<h:outputLabel id="out" value="#{bean.text}" />
</h:form>
and here is the changeText Method:
public void changeText() throws InterruptedException{
text = "test1";
FacesContext.getCurrentInstance().renderResponse();
Thread.sleep(2000);
text = "test2";
}
Now is it possible to set the output label (id = out) to be rendered (or changed) to "test1", then after the 2 second have elapsed it changes to "test2"? Well looking at the JSF life cycle i thought it isnt possible, but maybe i got the life cycle wrong, or one of you guys know a work around.
Upvotes: 0
Views: 147
Reputation: 1109112
No, that's not possible. The render response only starts once the action method returns.
There are basically 2 ways to achieve the desired behavior: polling or pushing. Based on your question history, you're using Java EE 7 + JSF 2.2 + PrimeFaces. You could for pushing use PrimeFaces <p:socket>
or homegrow one using Java EE 7's new WebSocket API (JSR-356).
Upvotes: 1