11 Replies Latest reply: Aug 1, 2013 12:11 PM by MobileADFDev RSS

    Scope Issues in ADF Mobile

    MobileADFDev

      Making the thread seperate for the second question in this thread. https://forums.oracle.com/message/11097822#

       

      New question is,

       

      How to make sure an instance of the Bean is not created when i go to a new AMX page. I tried to use all scopes (PageFlow and Application) of the bean but all of them create a new instance of the bean when the control comes into the next page. So whatever variables i set in the first page is not passed over to the next page. below is how i wrote my app.

       

      Click a button on FirstPage to call a bean's method using actionListener -> The method in SampleBean call DB function and set values to the member variables in this bean -> Will go to Second Page based on the taskflow's action.

       

      I have added the code in here as TestNestedIterator2.zip,

        • 1. Re: Scope Issues in ADF Mobile
          ArunBabu

          Code is not accessible. It is protected by some username/password

          • 2. Re: Scope Issues in ADF Mobile
            MobileADFDev

            I have updated the link to use the public page. Please download TestNestedIterator2.zip.

            • 3. Re: Scope Issues in ADF Mobile
              MobileADFDev

              Arun, did you find anything?

              • 4. Re: Scope Issues in ADF Mobile
                Frank Nimphius-Oracle

                Hi,

                 

                the new link doesn't render as a link and thus doesn't allow a download of the test case. Interestingly the first now started working. Just in case Arun listens.

                 

                Frank

                • 5. Re: Scope Issues in ADF Mobile
                  Frank Nimphius-Oracle

                  Hi,

                   

                  apparently you configured the same object as a data control and a managed bean. Seems that in ADF mobile the two look at the same POJO instance at runtime. Because the binding layer however is in request scope this leads to a a re-instantiation of the Java bean.

                   

                  In your testcase I did remove all the binding references on the page and it worked as expected. So if there is a bug to report then its obviously that the binding and the managed bean only instantiate a single instance of a Java Bean. On the other side, I don't see using managed beans and ADF data controls to pointing to the same Java class as good practices (in web based ADF it creates two instances of the Java bean object, which also is not what people expect: they usually expect this to be a good idea for sharing data between data controls and managed beans).

                   

                  As a general recommendation out of this (and salted with common sense) I suggest to not share the same Java object as a managed bean and as a data control because of the different lifecycles.

                   

                  Frank

                  • 6. Re: Scope Issues in ADF Mobile
                    Frank Nimphius-Oracle

                    Hmmm,

                     

                    seems i was too cheerful of my finding. Though I think I am right with my recommendation to not use JavaBeans as DC and as managed beans , I have problems reproducing my result from the previous test. So I think we need to prove it in a simpler test case that is

                     

                    - 2 pages

                    - 1 managed bean in pageFlowScope

                    - a message set in page 1 and displayed in page 2

                     

                    If the above succeeds then the scopes work correct. If this testcase doesn't work then there obviously is a problem with the scopes in ADF Mobile. In the case where this works correct, in a second step one can create a data control from the bean defined as the managed bean to see if there is a lifecycle conflict

                     

                    Frank

                    • 7. Re: Scope Issues in ADF Mobile
                      ArunBabu

                      Hi Frank,

                       

                      I had seen the project shared by original poster but since I havent ever tried using the same class as both managed bean and dc , i just avoided replying. Also frankly i didnt get the point being tried to prove with the shared project.

                       

                      Anyway I created a sample project exhibiting the test cases as you told above. When simply setting a property of a bean in pageFlowScope it is persisting to the next page. ( We have used this many times and this has to work )

                       

                      In the next case I exposed the same bean as DC and again added set a field via the DC in the UI. But both the value set though the managed bean and the dc persisted to the next page. It seems seperate instances are being created of the sam java class for bean and dc. I have attached the sample project. So it seems there are no issues here! https://docs.google.com/file/d/0BwccZv980zlFWFEzejc5c2JXOW8/edit?usp=sharing

                       

                      Also your first explanation looked pretty convincing BTW

                       

                      Please let me know if I am missing any points.

                       

                      Thanks

                      Arun

                      • 8. Re: Scope Issues in ADF Mobile
                        MobileADFDev

                        Arun, Can you please explain why my code is not working as expected? I tried to remove the DC, but still getting the same results (the values set in the bean are not displayed in the next page). Also when i remove the DC i think the pagedef which refer the same gives null pointer exception. so what should i do?

                         

                        If you can just give me instructions on what to do in my sample project to make the scope to work that would be great.

                        • 9. Re: Scope Issues in ADF Mobile
                          ArunBabu

                          Add the below code in generate report.java . Since the variable is declared in pageFlowScope it's value is cached by default so you have to firePropertyChange to the UI to refresh the value there. You had added the call for propertyChangeSupport.firePropertyChange but you missed the below part. If you had automatically generate the code to notify listeners jdev should have done it for you.

                           

                              public void addPropertyChangeListener(PropertyChangeListener l) {

                                  propertyChangeSupport.addPropertyChangeListener(l);

                              }

                           

                           

                              public void removePropertyChangeListener(PropertyChangeListener l) {

                                  propertyChangeSupport.removePropertyChangeListener(l);

                              }

                           

                          As Frank said, using same java class as bean as well as DC may not be a good design practice but it should work without any issue. So please seperate your generateReport code into a bean and dc as you see fit.

                           

                          Thanks

                          Arun

                          • 10. Re: Scope Issues in ADF Mobile
                            MobileADFDev

                            It worked...Thanks Arun and Frank.

                            • 11. Re: Scope Issues in ADF Mobile
                              MobileADFDev

                              Arun, can you please take a look at another issue i posted in this thread? https://forums.oracle.com/thread/2563810