3 Replies Latest reply: Mar 28, 2013 5:00 AM by gimbal2 RSS

    can we access the session scoped variable by simply using its name

    Moazzam
      The Java EE 6 Tutorial contains a "Duke's Bookstore Case Study Example”. I could not understand following statements of this case study:

      *bookdetails.xhtml*

      {code}
      <h:outputText value="#{selected.title}"/>
      {code}

      *BookstoreBean.java*

      {code}
      public String details() {
      context()
      .getExternalContext()
      .getSessionMap()
      .put(
      "selected",
      getFeatured());

      return ("bookdetails");
      }
      {code}

      I want to know can we access the session scoped variable in bookdetails.xhtml by simply using its name as done above?
        • 1. Re: can we access the session scoped variable by simply using its name
          gimbal2
          I want to know can we access the session scoped variable in bookdetails.xhtml by simply using its name as done above?
          Why are you asking this? The example you post is showing exactly that you CAN do it. If you don't want to believe the example - deploy it and run it, or buy a book, or read the JSF specifications.
          • 2. Re: can we access the session scoped variable by simply using its name
            Moazzam
            I have deployed it and executed it. It's working fine.

            I just want to verify if my understanding about the topic is correct. I think that there is no configuration required for this feature. Can we use this syntax in any JSF application or only when CDI(context and dependency injection) is being used.
            • 3. Re: can we access the session scoped variable by simply using its name
              gimbal2
              It is basic Expression Language (EL) functionality, it isn't even specific to JSF. And it isn't specific to the session scope either, you can put beans in any scope (page, request, session, application, flash, conversation, whatever custom scope you create) and reference it using EL by only its name. The thing that you have to take care of is that the bean lives in SOME scope, which can be achieved using JSF specific annotations or configuration files, through CDI or by manually putting the bean in a specific scope through Java code. It's flexible, which is the nature of the Java platform.