I use tip from this post https://stackoverflow.com/a/13838907 to open new tab, however when I go back to old one I get nullPointerException and my ViewScoped bean data are lost.
<h:form target="_blank">
<p:commandButton value="open new tab" action="#{otherBean.newTab}" ajax="false" />
</h:form>
<h:form>
<p:commandButton value="this wll cause NPE" action="#{pageBean.action}"/>
</h:form>
Click first button, go back to previous tab, click second button. PageBean is created once again and all data are lost. Both beans are ViewScoped.
Indeed, the view scoped bean in the initial tab/window get killed by returning a
Stringnavigation case outcome. You would like to returnnullorvoidto keep it alive. Based on thenewTab()code as shown in your other question, you need to replace the navigation case by aFaces#redirect()call (assuming that it’s indeed OmniFaces which you’re using there forFaces#setFlashAttribute()). You only need to setFlash#setRedirect()totruebeforehand to instruct the flash scope that a redirect will occur.