I'm experiencing strange behaviour with my session scoped bean. I used following imports and annotations to make it sessionscoped:
EDIT : more Code
import javax.enterprise.context.SessionScoped;
import javax.inject.Named;
@Named
@SessionScoped
public class DetailsBean implements Serializable {
private LinkedHashMap<String, String> folder;
@Inject
private ApplicationBean appBean;
@Inject
private UserBean userBean;
@PostConstruct
public void resolveID() {
this.folder = new LinkedHashMap<String, String>();
for (LinkedHashMap<String, String> tempfolder : appBean.getRepositoryContent()) {
if (tempfolder.get("text:nodeid").equals(URLid)) {
this.folder = tempfolder;
}
}
}
Code Snippet of JSF page :
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:rich="http://richfaces.org/rich">
<f:metadata>
<f:viewParam name="id" value="#{detailsBean.URLid}" required="true" requiredMessage="You must provide an Object Id"/>
<f:event type="preRenderView" listener="#{detailsBean.resolveID}" />
</f:metadata>
<h:head>
<title>Dataset #{detailsBean.name}</title>
</h:head>
<h:body>
<h:form>
<h:panelGrid columns="2" columnClasses="fixed-column">
Name <h:inputText value="#{detailsBean.name}"
id="name" required="true"
requiredMessage="name required"/>
<rich:message for="name" ajaxRendered="true"/>
</h:panelGrid>
</h:body>
</h:form>
</html>
Now when I click on a link in my jsf page such a DetailsBean gets instantiated. When I click on another link with different content the same bean is used because I am still within the same Session. Now the strange thing is that even though I created 2 different browser tabs they show different content even after refreshing the page. How can the same bean instance show different contents ? I thought normally only a @ViewScoped bean could achieve this ? Don't get me wrong I DO want them to show different content so @ViewScoped would be the right decision to use here but I just wonder how this is possible...
EDIT2 : When I use javax.faces.ViewScoped, above Code doesn't work anymore (I get java.io.NotSerializableException because of the LinkedHashMap then)