8 Replies Latest reply on Oct 25, 2007 5:59 AM by Koen Verhulst

    JSF requestScope/sessionScope/applicationScope implicit objects

    Chris Muir-Oracle
      The JSF 1.1 spec under section 5.3.1.3 says that a managed bean created within a particular scope, be it a request, session or application scope, should be available through the corresponding EL implicit object requestScope, sessionScope or applicationScope respectively.

      As an example I've created the following simple bean:
      public class MyBean {
        public MyBean() { }

        String myValue = "a value";

        public void setMyValue(String myValue) { this.myValue = myValue; }
        public String getMyValue() { return myValue; }
      }
      ....and configured it my faces-config.xml file as:
      <managed-bean>
        <managed-bean-name>myBean</managed-bean-name>
        <managed-bean-class>MyBean</managed-bean-class>
        <managed-bean-scope>request</managed-bean-scope>
      </managed-bean>
      ....finally referencing it within my ADF Faces page using:
      <af:inputText value="#{requestScope.myBean.myValue}"/>
      But it throws:
      javax.faces.el.PropertyNotFoundException: Error testing property 'myValue' in bean of type null
      at com.sun.faces.el.PropertyResolverImpl.isReadOnly(PropertyResolverImpl.java:274)
      ...and so on
      I know that I can actually access the bean as #{myBean.myValue}, but my understanding from the JSF spec is that the requestScope approach should work.

      What am I doing wrong here? Is it that only attributes, be they Strings or whatever, rather than fully blown objects (be it a backing bean), are accessible via the request/session/applicationScope implicit objects?

      Regards,

      CM.
        • 1. Re: JSF requestScope/sessionScope/applicationScope implicit objects
          Brenden Anstey
          Hi Chris,

          there must be some way for the faces controller to know to instantiate your bean when the page is called for the request.

          In the case of a backing bean Jdev puts a comment down the bottom of the page:
          <%-- 
            oracle-jdev-comment:preferred-managed-bean-name:userInfo
          --%> 
          I am guessing that this would be function as a jsp:usebean?

          Out of interest does adding this or a
          <jsp:useBean id="myBean" class="MyBean" scope="request"/>
          make any differnce?

          cheers,
          Brenden
          • 2. Re: JSF requestScope/sessionScope/applicationScope implicit objects
            Chris Muir-Oracle
            Hi Brenden

            From what I can read in the spec if you don't include the requestScope prefix in the EL, the faces controller is meant to search the requestScope, sessionScope then applicationScope to find the bean if already instantiated, otherwise search the faces-config.xml file for a <managed-bean> of the same name and instantiate, otherwise throw an error.

            So is my problem as you've indicated in your post, by being explicit about the requestScope, I'm bypassing the above facility, in particular the search & instantiate from the faces-config.xml entry?... thus why I need to include the code you've shown.

            Oversight in the spec if you ask me. If it doesn't exist in the requestScope it should go straight to the faces-config.xml file to see if it can create it. The whole point of EL was so you don't have to include the <jsp:useBean> tag, but instead rely on the faces controller to take care of it..... but in turn I guess there is an easy workaround; don't specificy the scope in the EL.

            For the record oracle-jdev-comment pragma doesn't work, but the <jsp:useBean> bean does. What's the XML equivalent for the oracle-jdev-comment pragma?... and I assume it's meant to go at the end of JSF/JSP page after the </f:view> and before the </jsp:root>?

            Also, I haven't seen the oracle-jdev-comment pragma before. Where did you discover this? Google doesn't reveal much.

            Ta,

            CM.
            • 3. Re: JSF requestScope/sessionScope/applicationScope implicit objects
              Brenden Anstey
              Hi Chris,

              I believe JDev adds the pragma if you elect to automatically expose components to a backing bean or double click on a command link and bind it to a backing bean.

              I just tested adding a command link to a jsp with no backing bean and no pragma. Double clicking on the command link and creating a backing bean automatically added the pragma to the JSP....

              It seems that it doesnt do this for the binding editor?

              cheers,
              B.
              • 4. Re: JSF requestScope/sessionScope/applicationScope implicit objects
                Chris Muir-Oracle
                Hi Brenden

                Hmmm, didn't know about the double clicking facility. Nice.

                Still can't get it to generate the pragma though. Not to worry, I think the answer if use the <jsp:bean> tag for now. Just finishing up a blog entry now and will link to this post.

                Thanks for your help :)

                Regards,

                CM.
                • 5. Re: JSF requestScope/sessionScope/applicationScope implicit objects
                  Chris Muir-Oracle
                  And here's the post:

                  http://one-size-doesnt-fit-all.blogspot.com/2007/03/some-explicit-language-about-implicit.html

                  Cheers,

                  CM.
                  • 6. Re: JSF requestScope/sessionScope/applicationScope implicit objects
                    594569
                    Hi Chris,

                    Thanks for the link. I have a simular error as yours, my situation is (I am currently using JDeveloper 10.1.3.3.0.4157)

                    Error Description:

                    500 Internal Server Error
                    javax.faces.el.PropertyNotFoundException: Error testing property 'inputValue' in bean of type null     at com.sun.faces.el.PropertyResolverImpl.isReadOnly(PropertyResolverImpl.java:274)     at oracle.adfinternal.view.faces.model.FacesPropertyResolver.isReadOnly(FacesPropertyResolver.java:124)     at com.sun.faces.el.impl.ArraySuffix.isReadOnly(ArraySuffix.java:236)
                    etc..........

                    My jspx input field defined as:

                    <af:selectInputText value="#{bindings.argMctry.inputValue}"
                    label="Country/Org"
                    columns="30"
                    binding="#{backing_app_Common_MissionSearch.ctryIn}"
                    id="ctryIn" windowHeight="600"
                    windowWidth="350"
                    returnListener="# {backing_app_Common_MissionSearch.handleCtry}"
                    action="dialog:openMCtry"/>
                    etc......

                    My managed bean in faces_config.xml :

                    <managed-bean>
                    <managed-bean-name>backing_app_Common_MissionSearch</managed-bean-name>
                    <managed-bean-class>tomis2.menus.navigation.view.backing.app.Common.MissionSearch</managed-bean-class>
                    <managed-bean-scope>request</managed-bean-scope>
                    <!--oracle-jdev-comment:managed-bean-jsp-link:1app/Common/MissionSearch.jspx-->
                    </managed-bean>
                    etc..........

                    I am new to Jdev, I appreciate your help to resolve this Oracle pragma.

                    Thank you very mucjh for your help.
                    • 7. Re: JSF requestScope/sessionScope/applicationScope implicit objects
                      594569
                      Hi Brenden,

                      Thru google, I discover that you help Chris Muir to resolve the Oracle pragma (?). I am new to Jdev and have a simular situation with JDeveloper 10.1.3.3.0.4157 as follows:

                      Error Description:

                      500 Internal Server Error
                      javax.faces.el.PropertyNotFoundException: Error testing property 'inputValue' in bean of type null     at com.sun.faces.el.PropertyResolverImpl.isReadOnly(PropertyResolverImpl.java:274)     at oracle.adfinternal.view.faces.model.FacesPropertyResolver.isReadOnly(FacesPropertyResolver.java:124)     at com.sun.faces.el.impl.ArraySuffix.isReadOnly(ArraySuffix.java:236)
                      etc..........

                      My jspx input field defined as:

                      <af:selectInputText value="#{bindings.argMctry.inputValue}"
                      label="Country/Org"
                      columns="30"
                      binding="#{backing_app_Common_MissionSearch.ctryIn}"
                      id="ctryIn" windowHeight="600"
                      windowWidth="350"
                      returnListener="# {backing_app_Common_MissionSearch.handleCtry}"
                      action="dialog:openMCtry"/>
                      etc......

                      My managed bean in faces_config.xml :

                      <managed-bean>
                      <managed-bean-name>backing_app_Common_MissionSearch</managed-bean-name>
                      <managed-bean-class>tomis2.menus.navigation.view.backing.app.Common.MissionSearch</managed-bean-class>
                      <managed-bean-scope>request</managed-bean-scope>
                      <!--oracle-jdev-comment:managed-bean-jsp-link:1app/Common/MissionSearch.jspx-->
                      </managed-bean>
                      etc..........

                      I appreciate your help to resolve this Oracle problem.

                      Thank you very mucjh for your help.
                      • 8. Re: JSF requestScope/sessionScope/applicationScope implicit objects
                        Koen Verhulst
                        Hi,

                        Double clicking a button makes sure a binding property is available in the faces-config.xml. After that your able to work with the binding container in the managed bean.
                        <managed-bean>
                            <managed-bean-name>myClass</managed-bean-name>
                            <managed-bean-class>com.company.view.beans.MyClass</managed-bean-class>
                            <managed-bean-scope>request</managed-bean-scope>
                            <managed-property>
                              <property-name>bindings</property-name>
                              <value>#{bindings}</value>
                            </managed-property>
                          </managed-bean>
                        If you do want to create the pragma, you need to make sure automatic component binding for a certain page is enabled. You can do this while creating a new page.
                        Notice the pragma will be created.

                        Regards,

                        Koen Verhulst