B4J Question [AbMaterial] NavigateToPage Problem (B4J 9.8 ABM 5.0)

vp2020

Member
Licensed User
Hi,
I have installed B4J 9.8 and downloaded ABMaterial 5.0 library and www5.0,
I found that the first click navigation bar item to another page would remained on the same page,
the app would navigate to the other page only if the second click was made.

My app runs fine on B4J 9.5 ABMaterial 4.95 Java 8 + conscrypt
Any idea how to solve it?
 

vp2020

Member
Licensed User
my code:

B4x:
Sub Page_NavigationbarClicked(Action As String, Value As String)
 
    page.SaveNavigationBarPosition
   
    If Action = "sbContact" Then Return

    If Action = "sbProfile" Then Return

    If Action = "sbLogOff" Then
        page.Msgbox2("sbLogOff","Sure to log off?","myApp","OK","Cancel",False,ABM.MSGBOX_TYPE_QUESTION,False,ABM.MSGBOX_POS_CENTER_CENTER,"")
        Return
    End If
    ABMShared.NavigateToPage(ws, ABMPageId, Value)
   
End Sub

Public Sub NavigateToPage(ws As WebSocket, PageId As String, TargetUrl As String) 'ignore
    Dim testTargetUrl As String = TargetUrl
    If Not(testTargetUrl.EndsWith(".htm") Or testTargetUrl.EndsWith(".html") Or testTargetUrl.EndsWith("/")) Then
        TargetUrl = TargetUrl & "/"
    End If
    If PageId.Length > 0 Then ABM.RemoveMeFromCache(CachedPages, PageId)
    If ws.Open Then
        ' it doesn't keep navigation history in the browser (the back button exists the application)
        'ws.Eval("window.location.replace(arguments[0])", Array As Object(TargetUrl))
        ' if you need browser history just comment the lines above and uncomment the lines below
        ' it keeps the navigation history in the browser
        ws.Eval("window.location = arguments[0]", Array As Object(TargetUrl))
        ws.Flush
        ws.Close ' ALSO NEW 4.00
    End If
End Sub

there is an error in log file:
--log--
~l027340033 Connected

Waiting for value (4 ms)
java.lang.RuntimeException: java.lang.RuntimeException: Object should first be initialized (HttpSession).
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:140)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:98)
at anywheresoftware.b4j.object.WebSocketModule$Adapter$ThreadHandler.run(WebSocketModule.java:204)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.RuntimeException: Object should first be initialized (HttpSession).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:49)
at anywheresoftware.b4j.object.HttpSessionWrapper.getIsNew(HttpSessionWrapper.java:111)
at b4j.eResult.classespage._websocket_connected(classespage.java:331)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
... 7 more
~l027405569 Disconnected

~l027340033 Connected

Waiting for value (0 ms)
~l027405569 Disconnected

~l027340033 Connected

Waiting for value (0 ms)
~l027405569 Disconnected

~l025373953 Connected

Waiting for value (1 ms)
Waiting for value (1 ms)
Waiting for value (1 ms)
~l025439489 Disconnected

~l02917505 Connected

Waiting for value (1 ms)
UpdateFromCache: LoginPage9eebf09e-3e71-4d79-ac97-9de0e6d686a9
Saving the first instance
Waiting for value (2 ms)
~l02917537:LoginPage9eebf09e-3e71-4d79-ac97-9de0e6d686a9
--log---

I also tested ABMaterial Demo from ABMaterial 4.51 after deleted original css,js,font folders under www folder
and replaced the folders from www5.0, then the same behavior was observed,
only second click would change the page.
 
Upvote 0

MichalK73

Well-Known Member
Licensed User
Longtime User
I just mean it.
In 'ABMShared.NavigateToPage' I think I've re-routed the lines ws.flush at the end of the function and it works. I can't tell you exactly because I can't see my sources right now.
 
Upvote 0

Philip Chatzigeorgiadis

Active Member
Licensed User
Longtime User
A temporary solution I have right now is the following (although, in my case, it took 2 clicks to change page, but no error appeared in the logs)
In ABMShared.NavigateToPage sub, I commented the line 20 shown below and uncommented line 15

B4X:
'----------------------START MODIFICATION 4.00-------------------------------
Public Sub NavigateToPage(ws As WebSocket, PageId As String, TargetUrl As String) 'ignore
    Dim testTargetUrl As String = TargetUrl
'    Log("Target Url: " & TargetUrl)
    If Not(testTargetUrl.EndsWith(".htm") Or testTargetUrl.EndsWith(".html") Or testTargetUrl.EndsWith("/")) Then
        TargetUrl = TargetUrl & "/"
    End If
'    Log("Target Url: " & TargetUrl)
    If PageId.Length > 0 Then ABM.RemoveMeFromCache(CachedPages, PageId)
    If ws.Open Then
'        Log("fire")
        ' it doesn't keep navigation history in the browser (the back button exists the application)
     
        'UNCOMMENTED THIS LINE
        ws.Eval("window.location.replace(arguments[0])", Array As Object(TargetUrl))
        ' if you need browser history just comment the lines above and uncomment the lines below
        ' it keeps the navigation history in the browser
     
        'COMMENTED THIS LINE
        'ws.Eval("window.location = arguments[0]", Array As Object(TargetUrl))
     
     
        ws.Flush    
        ws.Close ' ALSO NEW 4.00
    End If
End Sub
'----------------------END MODIFICATION 4.00-------------------------------
 
Last edited:
Upvote 0

MichalK73

Well-Known Member
Licensed User
Longtime User
Hello.
When possible, could you please share your solution?
Thanks.
B4X:
'----------------------START MODIFICATION 4.00-------------------------------
Public Sub NavigateToPage(ws As WebSocket, PageId As String, TargetUrl As String) 'ignore   
    Dim testTargetUrl As String = TargetUrl
    If Not(testTargetUrl.EndsWith(".htm") Or testTargetUrl.EndsWith(".html") Or testTargetUrl.EndsWith("/")) Then
        TargetUrl = TargetUrl & "/"
    End If
    If PageId.Length > 0 Then ABM.RemoveMeFromCache(CachedPages, PageId)
    If ws.Open Then
        ' it doesn't keep navigation history in the browser (the back button exists the application)
        'ws.Eval("window.location.replace(arguments[0])", Array As Object(TargetUrl))
        ' if you need browser history just comment the lines above and uncomment the lines below
        ' it keeps the navigation history in the browser
        ws.Eval("window.location = arguments[0]", Array As Object(TargetUrl))
        ws.Flush
'        ws.Close ' ALSO NEW 4.00   
        ' note that this error can be ignored anyway
        ' if you are bothered by the warning error you get with this close, you can try to replace it with this:
                
        Sleep(50)
        If ws.Open Then
            Log("closing the websocket, in case the eval does not do it...")
            ws.Close ' ALSO NEW 4.00
        End If
    End If   
End Sub

This is how the transition between the NavigatorBar in ABM 5.0 works for me
 
Upvote 1
Top