B4J Question [ABMaterial] Reload a page without using Cache [Solved]

Anser

Well-Known Member
Licensed User
Longtime User
Hi,

I do re-load the page by using the following code
B4X:
ABMShared.NavigateToPage(ws,"" ,"./")

This is reloading the page, but it is still reading from the Cache hence the charts/graphs are not refreshed with the new values. Here are the log entries that are generated when I call ABMShared.NavigateToPage(ws,"" ,"./")
B4X:
Disconnected
Inside Build page
Connected
Waiting for value (7 ms)
UpdateFromCache: TargetService36deaf6d-2872-4012-95c0-b52da9f65fe2
Reading from cache
Comes from cache
Waiting for value (8 ms)
TargetService36deaf6d-2872-4012-95c0-b52da9f65fe2

Whereas if I refresh the page using the reload button available in the Chrome, then the contents (Charts) are refreshed with the new values.

Now my question is : Is there any way to avoid the cache willingly when I call
B4X:
ABMShared.NavigateToPage(ws,"" ,"./")

I did not find any other methods like page.reload. I even tried page.row(1).Refresh but no result.
 

Anser

Well-Known Member
Licensed User
Longtime User
When we reload the page like this way
B4X:
ABMShared.NavigateToPage(ws, ABMPageId,"./")
The browser back button has to be clicked twice to go back to the previous page. Is this the normal behavior ? Or is there any other trick to resolve this, so that it works like the normal page :)
 
Upvote 0

Anser

Well-Known Member
Licensed User
Longtime User
Where do you do that (in a button click or so?).
I use the Reload button on the Chrome browser
Annotation 2018-11-28 160240.jpg
 
Upvote 0

Anser

Well-Known Member
Licensed User
Longtime User
In the Class Globals, I added Private ABMPageId As String = "ts"
B4X:
Sub Class_Globals
    Private ws As WebSocket 'ignore
    ' will hold our page information
    Public page As ABMPage
    ' page theme
    Private theme As ABMTheme
    ' to access the constants
    Private ABM As ABMaterial 'ignore
    ' name of the page, must be the same as the class name (case sensitive!)
    Public Name As String = "TargetService"  '<-------------------------------------------------------- IMPORTANT
    ' will hold the unique browsers window id
    Private ABMPageId As String = "ts"
    ' your own variables
End Sub
In the RadioGroup Click event, I call ABMShared.NavigateToPage(ws, ABMPageId,"./") as shown below
B4X:
Sub radiotrgttype_Clicked(Target As String)
   
    Dim radiotrgttype As ABMRadioGroup = page.Component("radiotrgttype")
    nTargetType = radiotrgttype.GetActive()
    ws.Session.SetAttribute("TargetType", nTargetType )
   
    'Reload the page
    ABMShared.NavigateToPage(ws,ABMPageId ,"./")

End Sub
When I do a page reload with ABMShared.NavigateToPage(ws,ABMPageId ,"./"), to go back to the previous page using the Chrome browsers' back button, the first click does not takes to the previous page, instead I have to repeat the back button click once more
 
Last edited:
Upvote 0

Anser

Well-Known Member
Licensed User
Longtime User
I use the Reload button on the Chrome browser
View attachment 74810
In the post #5 of this thread, I have used the word "Reload" instead of "Back button" and highlighted (yellow) the wrong button too. I think I need some rest :)
Here is the correct image
Annotation 2018-11-28 164636.jpg

Hope it is clear to you now. After reloading the page programatically using ABMShared.NavigateToPage(ws,ABMPageId ,"./"), I cannot go back to previous page with one single click using the back button in the browse, instead I have to click the back button twice. In the first click it will reload the same page itslelf
 
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
Apart from your back button problem (but maybe it helps), this is very bad:

B4X:
Private ABMPageId As String = "ts"

You should leave the existing ABMPageID you've got from ABMPageId = ABM.GetPageID(page, Name,ws) in Websocket_Connected.

If you use something fixed like 'ts', then you cannot have multiple users going to the same page without destroying each others data.
 
Upvote 0

Anser

Well-Known Member
Licensed User
Longtime User
If you use something fixed like 'ts', then you cannot have multiple users going to the same page without destroying each others data.
Thank you for correcting me. I changed as per your suggestion.
Going back to the previous page with one single click on the Back button is still not resolved. It doesn't matter how many times you reloaded the page using
ABMShared.NavigateToPage(ws,ABMPageId ,"./"), the back button on the browser needs to be clicked twice to go back to the previous page.
 
Upvote 0

Anser

Well-Known Member
Licensed User
Longtime User
Is there a way/setting to make a particular page never load from cache ? ie always fresh loading
 
Upvote 0

Anser

Well-Known Member
Licensed User
Longtime User
It looks like when a page is loaded from Cache, the Sub ConnectPage() is not executed. For eg, if you have a page.ShowModalSheet("login") in the ConnectPage, then it is not executed
 
Upvote 0

Anser

Well-Known Member
Licensed User
Longtime User
Is there a way/setting to make a particular page never load from cache ? ie always fresh loading
Is this possible ?. ie Whenever a page is loaded, it should never load from cache ? Any specific setting to do this for a particular, I mean not for all the pages, ONLY for certain pages.
My problem is that I have a Custom Login Page
I have the following flow
My Custom Login Page -> Home Page (Home page has Navigation bar to navigate to different pages)
On all the pages I have a given the option to Logoff ON the NavigationBar TopItem. If the user clicks on it it should log off and then the Login page with the Login prompt should appear
B4X:
page.NavigationBar.AddTopItemEx("AppLogOff", "Logout", "mdi-action-input", "", ABM.VISIBILITY_ALL,ABM.COLOR_WHITE, "", ABM.ICONALIGN_LEFT)
On each and every page's Page_NavigationbarClicked, I have the following code
B4X:
' clicked on the navigation bar
Sub Page_NavigationbarClicked(Action As String, Value As String)
    ' saving the navigation bar position
    page.SaveNavigationBarPosition
   
    If Action = "AppLogOff" Then
        ABMShared.AppLogOff(page)
        Return
    End If

    ABMShared.NavigateToPage(ws, ABMPageId, Value)
End Sub
This is the code for AppLogOff in ABMShared
B4X:
Sub AppLogOff(page As ABMPage) 'ignore
    ' do whatever you have to do to log off your user
    page.ws.Session.SetAttribute("UserID", 0)
    page.ws.Session.SetAttribute("AppType", "")
    page.ws.Session.SetAttribute("DirectLogin", 0)
   
    Dim LoginPageID As String
    LoginPageID = page.ws.Session.GetAttribute("LoginPageID")

    NavigateToPage(page.ws, LoginPageID, "../Login/index.html")
End Sub
In the Sub AppLogOff() I should call the Login Page. I do not know how to get the PageID of the LoginPage inside ABMShared so that I could call for a page reload avoiding the cache. The login modal sheet is in the ConnectPage() of Login.

To overcome this issue what I have done is that In the Login page's ConnectPage() I save the PageID to a session variable and then in the Sub AppLogOff(), I use the saved PageID to reload the Login Page. I do not know whether what I have did is the correct way. OR Is there a better way to do this.
 
Upvote 0
Top