0

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)

nico1510
  • 606
  • 9
  • 29
  • It shouldn't be possible, but if you have some logic going on in your backer that you're not aware of, then it is possible. Please post more code. – Catfish Nov 13 '12 at 17:31
  • Ok I edited. The content on the jsf page uses the folder map and gets Strings from it. – nico1510 Nov 13 '12 at 17:47
  • Can you post the snippet of view code that uses this backing bean? – Catfish Nov 13 '12 at 17:54
  • I did...But it seems that only the view isn't right. When I do changes on the details site, only the last loaded site is updated – nico1510 Nov 13 '12 at 18:07

1 Answers1

-1

I believe you have error in import line. import javax.enterprise.context.SessionScoped;. You should import annotations from javax.faces.bean.SessionScoped.

piotrsPL
  • 17
  • 3
  • OP is managing bean by CDI `@Named`, not by JSF `@ManagedBean`. Even then, if the import was indeed wrong, it'd have defaulted to request scope and thus definitely not act like a view scoped one. – BalusC Dec 07 '12 at 19:49