I have a view where you can start an expensive process. The view is paired to a @ViewScoped bean, and if the process is started, the status is checked periodically with PrimeFaces's . I have the following Runnable
which calls a webservice with an expensive operation.
public class Generator extends AsyncCaller {
private Viewer bean;
private String id;
public Generator(Viewer bean, Client client, String id) {
super(client);
this.bean = bean;
this.id = id;
}
@Override
public void run() {
ClientResponse response = getClient().generate(this.id);
boolean error =
(response.getClientResponseStatus().getFamily() != Family.SUCCESSFUL);
if (error) {
Exception e = new UniformInterfaceException(response);
this.bean.setGenerateException(e);
}
this.bean.setGenerateError(error);
}
}
I start this Runnable
as a separate Thread
, so the UI is not blocked. As you can see I pass the view scoped managed bean instance to the Runnable
so if there is an error I can set it in the bean and later show it on the UI.
My problem is that with Mojarra 2.1.6 and 2.1.26 this works fine, but with MyFaces 2.1.13 – which I would prefer to use – the generateError
variable is never true
in the bean, although I can see setGenerateError(true)
called in debug. The actual bean that is used with the view is different from the bean instance that is accessible from the thread. I can actually see this in debug: with MyFaces, every poll request results in a new view scoped bean instance, whereas with Mojarra it is always the same instance.
Is there a <context-param />
setting in MyFaces that I am missing? Which one is actually the correct behaviour as per specification?
Found the answer in the OmniFaces showcase's web.xml:
<context-param>
<!-- MyFaces and Mojarra don't agree on the default setting for actually
serializing state in the session as opposed to just storing a reference.
Mojarra's default is false, but can be switched to true. MyFaces' default
is true, and can be switched to false, which we thus do below. See http://arjan-tijms.omnifaces.org/p/jsf-22.html#1127 -->
<param-name>org.apache.myfaces.SERIALIZE_STATE_IN_SESSION</param-name>
<param-value>false</param-value>
</context-param>