5 Replies Latest reply on Oct 15, 2013 4:42 PM by Eddie Phan

    ADF Mobile - Get network status

    Eddie Phan

      OS: OSX 10.8.5

      JDEV: 11.1.2.4

      ADF Mobile Extension version: 11.1.2.4.39.64.51

       

      HI All,

       

      I'm currently in the middle of developing an ADF Mobile application and exploring the offline/online capabilities and have run into an issue where i'm trying to determine if the user has network connectivity, but its not working properly. I'm trying to make the app as dynamic as possible such that, for every transaction that requires network access, the app will check beforehand whether it is "connected" or "disconnected".  I've tried the following but not quite got there..

       

      1) From the link below, Joe does make note that the EL Expression "#{deviceScope.hardware.networkStatus}" to resolve the network status is only evaluated at start up, which is good for when the app opens.. but not good when the user loses network connectivity.

       

      Re: JDeveloper  ADF Mobile -- Android Context

       

      2) The link below uses javascript to evaluate the network connectivity. This works first time and every subsequent time afterwards, however, I would like the javascript to ONLY evaluate the network status and then populate a pageFlowScope variable with true or false. This bit also works fine. From here, it may seem that the pageFlowScope variable has been populated, but if the java method (which calls the javascript function to check the network connectivity) also includes code that reference the pageFlowScope variable that the javascript has just populated, it is not evaluated properly.

       

      Example:

          public void checkConnection(ActionEvent actionEvent) {

              // This works fine and populates the PageFlowScope variable fine

              AdfmfContainerUtilities.invokeContainerJavaScriptFunction("feature1", "application.checkConnection",

                                                                                new Object[] { });

             

              // The two lines below do not work properly, as if its retained the old value of the pageFlowScope.

              ValueExpression ve = AdfmfJavaUtilities.getValueExpression("#{pageFlowScope.isConnected}", String.class);

              throw new AdfException("isConnected: " + (String)ve.getValue(AdfmfJavaUtilities.getAdfELContext()), AdfException.INFO);

          }

       

      Unwinding ADF: Offline Data Synchronization for ADF Mobile

       

      Below is a link to a sample app that i made and the steps to reproduce:

      https://app.box.com/s/ng5n362unttu7b88i42b

       

      - Have network connectivity

      - Click on the "Check connection via JS' button the first time

      - The popup in the foreground is the javascript showing the connectivity, which is correct

      - The popup in the background is an INFO AdfExpection showing the connectivity, which is INCORRECT

      - Click OK twice

       

      - Click on the "Check connection via JS' button the second time

      - The popup in the foreground is the javascript showing the connectivity, which is correct

      - The popup in the background is an INFO AdfExpection showing the connectivity, which is CORRECT

      - Click OK twice

      - disconnect your computer from the network/internet

       

      - Click on the "Check connection via JS' button the third time

      - The popup in the foreground is the javascript showing the connectivity, which is correct

      - The popup in the background is an INFO AdfExpection showing the connectivity, which is INCORRECT

       

       

      Has anyone has similar use case has have a work around/solution? This is driving me nuts!

       

      Cheers,

      Eddie

        • 1. Re: ADF Mobile - Get network status
          Frank Nimphius-Oracle

          Hi,

           

          have you tried

           

          adf.mf.el.setValue( { "name": "#{pageFlowScope.myVariable}", "value": "some value" },   onSuccess, onFail);

           

          to set the pageFlowScope variable ?

           

          https://blogs.oracle.com/mobile/entry/invoking_custom_javascript_from_an

           

          I am not sure the method you used in your code does really update the managed bean instance. And if it does it for sure doesn't ensure the EL reference to be refreshed (property change). So have a go with the

           

           

          adf.mf.el.setValue( { "name": "#{pageFlowScope.myVariable}", "value": "some value" },   onSuccess, onFail);

           

          Frank

          • 2. Re: ADF Mobile - Get network status
            Eddie Phan

            Hi Frank,

             

            Thanks for the quick reply.

             

            That's exactly what i've used in my javascript function in my demo app and that link is the resource i used as well, however, that javascript code does populate the pageFlowScope variable fine, however, if i make reference to that pageFlowScope variable from within the same java method that includes the call to the javascript function, it does not get the updated pageFlowScope value. Only after the transaction has fully completed and i then [for example] click on a button on the screen to evaluate the pageFlowScope variable again, do i get the updated value.

             

            Having a stab in the dark, could it be something to do with the way the javascript is executed when updating the pageFlowScope variable and lifecycle of that transaction

             

            I've also tried this under the code where it populates the pageFlowScope, but it can't resolve the expression, seems like i'm doing something wrong..

             

            navigator.notification.alert('pageFlowScope value: ' + adf.mf.el.getValue("#{pageFlowScope.isConnected}", onSuccess, onFail), alertDismissed, 'Connected', 'OK');

            • 3. Re: ADF Mobile - Get network status
              Eddie Phan

              Any further help would be much appreciated

              • 5. Re: ADF Mobile - Get network status
                Eddie Phan

                ok, so after some more experimentation i found a solution

                 

                 

                So as of version 11.1.2.4, if you're using the built in EL expression to evaluate the network status, it will only be evaluated when the app starts up and does not re-evaluate the network status. Joe has mentioned in one of the links in my first post that it will be implemented in a later version, so this post may be redundant by the time you are reading this, but if Oracle have not fixed it, then this fix will still apply.

                 

                 

                Anywho, if you require to get the current network status, the best solution as of 11.1.2.4 would be to use javascript to get the current network status and create a pageFlowScope bean and have a variable in that bean to signify the network status and have the javascript call that setter... its the next logical step, but its odd that the pageFlowScope variable doesn't get updated/refreshed when using Javascript to assign a value to that variable, see original post for further details