Search code examples
jsf-2cdimojarraview-scope

ViewScoped bean on multiple browser tabs conflicts


I'm using JSF Mojarra 2.3.8 with Tomcat 8 (with additional libraries required for CDI and JPA). I have a ViewScoped bean:

@Named @ViewScoped
public class MyBean implements Serializable {
...

I have a page that uses this bean.

I open the page in 2 browser tabs, modify and post the page on tab 1. Then navigate away from the page on tab 1 (the action returns a different page).

Then, on tab 2, I try to modify and save the same record. There is no error, but I can see from the logs that MyBean is recreated and has lost the original data.

To save the data, I'm using:

<h:commandButton type="submit" value="Save" action="#{myBean.saveData}" />

I thought that ViewScoped beans could be used independently on multiple tabs. If that's true, why should one page affect the same bean associated with another page?

It seems that I have the same problem described here: Multiple browser tabs or windows with the same ViewScoped bean class but alas it has no answer.

Although this may share the same root cause as javax.faces.view.ViewScoped bean and multiple tabs issue I don't think it's a duplicate because I'm not using WildFly, so the answer for that question will be different to mine (i.e. WildFly was patched).


Solution

  • In case someone else has the same problem, I think this is the closest thing to an answer right now:

    This is a bug with Mojarra and will be fixed in 2.3.10 according to this post: https://github.com/eclipse-ee4j/mojarra/issues/4509#issuecomment-453188481

    Until Mojarra 2.3.10 is released, using the version that is shipped with WildFly 16 might work because the Wildfly team have patched that version (but I haven't tried that). If you're using Wildfly or Payara, then look into upgrading to the latest versions (16 Alpha 1 for WF) as they've both been patched (but not in GA as of this answer).

    UPDATE: Version 2.3.10 can be found at its new home: http://central.maven.org/maven2/org/glassfish/jakarta.faces/2.3.10/