B4J Question [ABMaterial] - Grid does not initialize properly

Rob White

Member
Licensed User
Hi all hope I have header correctly formatted. I am not sure how to flag this is a ABMaterial problem.

I have taken the template project and got it running in the IDE.
I have then created my own page using Project, add new model, class model and ABM web page called observ

here is my code

B4X:
'Class module
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 = "Observ"  '<-------------------------------------------------------- IMPORTANT
    ' will hold the unique browsers window id
    Private ABMPageId As String = ""
    ' your own variables 
  
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
    ' build the local structure IMPORTANT!
    BuildPage     
End Sub

#Region ABM
Private Sub WebSocket_Connected (WebSocket1 As WebSocket) 
    Log("Connected")
      
    ws = WebSocket1     
  
    ABMPageId = ABM.GetPageID(page, Name,ws)
  
    Dim session As HttpSession = ABM.GetSession(ws, ABMShared.SessionMaxInactiveIntervalSeconds)
    If session.IsNew Then
        session.Invalidate
        ABMShared.NavigateToPage(ws, "", "./")
        Return
    End If
      
    If ABMShared.NeedsAuthorization Then
        If session.GetAttribute2("IsAuthorized", "") = "" Then
            ABMShared.NavigateToPage(ws, ABMPageId, "../")
            Return
        End If
    End If     
    ABM.UpdateFromCache(Me, ABMShared.CachedPages, ABMPageId, ws)     
    If page.ComesFromPageCache Then
        ' when we have a page that is cached it doesn't matter if it comes or not from a new connection we serve the cached version.
        Log("Comes from cache")     
        page.Refresh     
        page.FinishedLoading     
    Else
        If page.WebsocketReconnected Then
            Log("Websocket reconnected")
            ' when we have a client that doesn't have the page in cache and it's websocket reconnected and also it's session is new - basically when the client had internet problems and it's session (and also cache) expired before he reconnected so the user has content in the browser but we don't have any on the server. So we need to reload the page.
            ' when a client that doesn't have the page in cache and it's websocket reconnected but it's session is not new - when the client had internet problems and when he reconnected it's session was valid but he had no cache for this page we need to reload the page as the user browser has content, reconnected but we have no content in cache
            ABMShared.NavigateToPage (ws, ABMPageId, "./" & page.PageHTMLName)
        Else
            ' when the client did not reconnected it doesn't matter if the session was new or not because this is the websockets first connection so no dynamic content in the browser ... we are going to serve the dynamic content...
            Log("Websocket first connection")
            page.Prepare
            ConnectPage         
        End If
    End If
    Log(ABMPageId)     
End Sub

Private Sub WebSocket_Disconnected
    Log("Disconnected")
End Sub

Sub Page_ParseEvent(Params As Map)
    Dim eventName As String = Params.Get("eventname")
    Dim eventParams() As String = Regex.Split(",",Params.Get("eventparams"))
  
    'log(eventName)
  
    If eventName = "beforeunload" Then
        Log("preparing for url refresh")
        ABM.RemoveMeFromCache(ABMShared.CachedPages, ABMPageId)
        Return
    End If
    Dim caller As Object = page.GetEventHandler(Me, eventName)
    If caller = Me Then
        If SubExists(Me, eventName) Then
            Params.Remove("eventname")
            Params.Remove("eventparams")
            If eventName = "page_dropped" Then
                page.ProcessDroppedEvent(Params)
            End If
            Select Case Params.Size
                Case 0
                    CallSub(Me, eventName)
                Case 1
                    CallSub2(Me, eventName, Params.Get(eventParams(0)))
                Case 2
                    If Params.get(eventParams(0)) = "abmistable" Then
                        Dim PassedTables As List = ABM.ProcessTablesFromTargetName(Params.get(eventParams(1)))
                        CallSub2(Me, eventName, PassedTables)
                    Else
                        CallSub3(Me, eventName, Params.Get(eventParams(0)), Params.Get(eventParams(1)))
                    End If
                Case Else
                    ' cannot be called directly, to many param
                    CallSub2(Me, eventName, Params)
            End Select
        End If
    Else
        CallSubDelayed2(caller, "ParseEvent", Params) 'ignore
    End If
End Sub

public Sub BuildTheme()
    ' start with the base theme defined in ABMShared
    theme.Initialize("pagetheme")
    theme.AddABMTheme(ABMShared.MyTheme)

    ' add your specific page themes
  
End Sub

public Sub BuildPage()
    ' initialize the theme
    Log("At Observ.BuildPage -------------------------------------------------------------------------")
    BuildTheme
  
    ' initialize this page using our theme
    page.InitializeWithTheme(Name, "/ws/" & ABMShared.AppName & "/" & Name, False, ABMShared.SessionMaxInactiveIntervalSeconds, theme)
    page.ShowLoader=True
    page.PageHTMLName = "index.html"
    page.PageTitle = "Observation"
    page.PageDescription = "Record observation on specific beast"
    page.PageKeywords = ""
    page.PageSiteMapPriority = ""
    page.PageSiteMapFrequency = ABM.SITEMAP_FREQ_YEARLY
      
    page.ShowConnectedIndicator = True
              
    ' adding a navigation bar
    'ABMShared.BuildNavigationBar(page, "My Page","../images/logo.png", "", "", "")
          
    ' create the page grid
#Region C:\CattleMan\V1\Cman\Grids\observ.abmgrid
    'PHONE
    '╔═══════════════════════════════════════════════════════════════════════════════════╗
    '║ 1,1                                                                               ║
    '║-----------------------------------------------------------------------------------║
    '║ 1,2                                     | 1,3                                     ║
    '║-----------------------------------------------------------------------------------║
    '║ 1,4                                                                               ║
    '║-----------------------------------------------------------------------------------║
    '║ 1,5                                                                               ║
    '║-----------------------------------------------------------------------------------║
    '║ 1,6                                            | 1,7                              ║
    '╚═══════════════════════════════════════════════════════════════════════════════════╝

    'TABLET
    '╔═══════════════════════════════════════════════════════════════════════════════════════════════════════════╗
    '║ 1,1                                                                                                       ║
    '║-----------------------------------------------------------------------------------------------------------║
    '║ 1,2                                                 | 1,3                                                 ║
    '║-----------------------------------------------------------------------------------------------------------║
    '║ 1,4                                                                                                       ║
    '║-----------------------------------------------------------------------------------------------------------║
    '║ 1,5                                                                                                       ║
    '║-----------------------------------------------------------------------------------------------------------║
    '║ 1,6                                                          | 1,7                                        ║
    '╚═══════════════════════════════════════════════════════════════════════════════════════════════════════════╝

    'DESKTOP
    '╔═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╗
    '║ 1,1                                                                                                                               ║
    '║-----------------------------------------------------------------------------------------------------------------------------------║
    '║ 1,2                                                             | 1,3                                                             ║
    '║-----------------------------------------------------------------------------------------------------------------------------------║
    '║ 1,4                                                                                                                               ║
    '║-----------------------------------------------------------------------------------------------------------------------------------║
    '║ 1,5                                                                                                                               ║
    '║-----------------------------------------------------------------------------------------------------------------------------------║
    '║ 1,6                                                                        | 1,7                                                  ║
    '╚═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝

    page.AddRows(1,True,"").AddCells12(1,"").AddCellsOS(2,0,0,0,6,6,6,"").AddCells12(2,"").AddCellsOS(1,0,0,0,7,7,7,"").AddCellsOS(1,0,0,0,5,5,5,"")
    page.BuildGrid ' IMPORTANT!
    Log("Grid built .......................")
#End Region
  
End Sub

public Sub ConnectPage()         
    '    connecting the navigation bar
    ' ABMShared.ConnectNavigationBar(page)
  

  
    ' refresh the page
    page.Refresh
    Dim lblTitle As ABMLabel
    'lblTitle.Initialize(page, "lblobservtitle", ABMShared.TitleStr("Observation"), ABM.SIZE_H3, True, "")
    lblTitle.Initialize(page, "lblobservtitle", "Temp title", ABM.SIZE_H3, True, "")
    ' Following "works" - Well no errors BUT can NOT see title
    page.Cell(1,1).AddComponent(lblTitle)
    ' BUT if you uncomment following & comment above an error occurs - Log shows message - No row found with rowId=R2!
    'page.Cell(2,1).AddComponent(lblTitle)
    Log("Should have title!")
    ' Tell the browser we finished loading
    page.FinishedLoading
    ' restoring the navigation bar position
    page.RestoreNavigationBarPosition 
End Sub
#end region

#Region ABMPage
' clicked on the navigation bar
Sub Page_NavigationbarClicked(Action As String, Value As String)
    ' saving the navigation bar position
    page.SaveNavigationBarPosition
    If Action = "LogOff" Then
        ABMShared.LogOff(page)
        Return
    End If

    ABMShared.NavigateToPage(ws, ABMPageId, Value)
End Sub

Sub Page_DebugConsole(message As String)
    Log("---> " & message)
End Sub
#end region

In ConnectPage() you will see some comments:-

If I try to create an ABMlabel and then place it in cell 1,1 I get a blank page (Well not quite I can see the green connect "light")

BUT

If I comment above line out and try to place the label in cell 2,1 I get a log error of "No row found with rowId=R2!"

Here is my complete log with fresh compile then view of page with Chrome (can see connect light).
I then changed the lines did a ctrl S and refreshed browser getting error.

B4X:
Waiting for debugger to connect...
Program started.
At Observ.BuildPage -------------------------------------------------------------------------
Grid built .......................
Start B4J Analyse!
When an error occurs, check the B4JAnalyse.log file in the Objects folder to see the last B4J line it was working on.
Collecting data from B4J source files... (1/2)
ABMShared.bas
DBM.bas
ABMCacheControl.bas
ABMErrorHandler.bas
ABMRootFilter.bas
ABMCacheScavenger.bas
ABMPageTemplate.bas
Observ.bas
AboutPage.bas
ABMApplication.bas
Cman.b4j
Analysing data from B4J source files... (2/2)
loading C:\CATTLE~1\V1\Cman\Objects: copymewithjar.needs...
Using cache system: 3.0
Needs material/awesome icons
Building C:\CATTLE~1\V1\Cman\Objects\copymewithjar.js.needs
Building core.min.1549675362959.css...
2019-02-09 12:22:44.179:INFO::main: Logging initialized @1864ms to org.eclipse.jetty.util.log.StdErrLog
2019-02-09 12:22:44.377:INFO:oejs.Server:main: jetty-9.4.z-SNAPSHOT; built: 2018-05-03T15:56:21.710Z; git: daa59876e6f384329b122929e70a80934569428c; jvm 11.0.1+13
2019-02-09 12:22:44.476:INFO:oejs.session:main: DefaultSessionIdManager workerName=node0
2019-02-09 12:22:44.477:INFO:oejs.session:main: No SessionScavenger set, using defaults
2019-02-09 12:22:44.480:INFO:oejs.session:main: node0 Scavenging every 660000ms
2019-02-09 12:22:44.537:INFO:oejsh.ContextHandler:main: Started o.e.j.s.ServletContextHandler@614ca7df{/,file:///C:/CattleMan/V1/Cman/Objects/www/,AVAILABLE}
2019-02-09 12:22:44.541:INFO:oejs.AbstractNCSARequestLog:main: Opened C:\CattleMan\V1\Cman\Objects\logs\b4j-2019_02_09.request.log
2019-02-09 12:22:44.842:INFO:oejs.AbstractConnector:main: Started ServerConnector@7b36aa0c{HTTP/1.1,[http/1.1]}{0.0.0.0:7200}
2019-02-09 12:22:44.843:INFO:oejs.Server:main: Started @2532ms
Emulated network latency: 100ms
2019-02-09 12:22:44.872:INFO:oejs.AbstractConnector:main: Stopped ServerConnector@7b36aa0c{HTTP/1.1,[http/1.1]}{0.0.0.0:7200}
2019-02-09 12:22:44.872:INFO:oejs.session:main: node0 Stopped scavenging
2019-02-09 12:22:44.876:INFO:oejsh.ContextHandler:main: Stopped o.e.j.s.ServletContextHandler@614ca7df{/,file:///C:/CattleMan/V1/Cman/Objects/www/,UNAVAILABLE}
2019-02-09 12:22:44.881:INFO:oejs.Server:main: jetty-9.4.z-SNAPSHOT; built: 2018-05-03T15:56:21.710Z; git: daa59876e6f384329b122929e70a80934569428c; jvm 11.0.1+13
2019-02-09 12:22:44.890:INFO:oejsh.ContextHandler:main: Started o.e.j.s.ServletContextHandler@614ca7df{/,file:///C:/CattleMan/V1/Cman/Objects/www/,AVAILABLE}
2019-02-09 12:22:44.892:INFO:oejs.AbstractNCSARequestLog:main: Opened C:\CattleMan\V1\Cman\Objects\logs\b4j-2019_02_09.request.log
2019-02-09 12:22:44.893:INFO:oejs.session:main: DefaultSessionIdManager workerName=node0
2019-02-09 12:22:44.893:INFO:oejs.session:main: No SessionScavenger set, using defaults
2019-02-09 12:22:44.893:INFO:oejs.session:main: node0 Scavenging every 600000ms
2019-02-09 12:22:44.898:INFO:oejs.AbstractConnector:main: Started ServerConnector@7b36aa0c{HTTP/1.1,[http/1.1]}{0.0.0.0:7200}
2019-02-09 12:22:44.898:INFO:oejs.Server:main: Started @2588ms
2019-02-09 12:22:44.899:INFO:oejs.session:main: node0 Scavenging every 900000ms
At Observ.BuildPage -------------------------------------------------------------------------
Grid built .......................
Connected
Waiting for value (101 ms)
Saving the first instance
Waiting for value (100 ms)
Websocket first connection
Waiting for value (100 ms)
Should have title!
Observ014efdc6-2eda-443c-965c-1b6199bec69c
preparing for url refresh
Disconnected
At Observ.BuildPage -------------------------------------------------------------------------
Grid built .......................
Connected
Waiting for value (101 ms)
Saving the first instance
Waiting for value (101 ms)
Websocket first connection
Waiting for value (101 ms)
Should have title!
Observ06b78092-7e33-4487-b372-c5bef0ca21d6
preparing for url refresh
Disconnected
At Observ.BuildPage -------------------------------------------------------------------------
Grid built .......................
Connected
Waiting for value (101 ms)
Saving the first instance
Waiting for value (100 ms)
Websocket first connection
Waiting for value (100 ms)
No row found with rowId=R2!
Cannot get methods of class: null, disabling cache.
Error occurred on line: 203
java.lang.NullPointerException
    at java.base/java.lang.Class.forName0(Native Method)
    at java.base/java.lang.Class.forName(Class.java:315)
    at anywheresoftware.b4a.shell.Shell$MethodCache.getMethod(Shell.java:870)
    at anywheresoftware.b4a.shell.Shell.getMethod(Shell.java:542)
    at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:673)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:240)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
    at jdk.internal.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
    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:91)
    at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
    at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:64)
    at com.ab.template.observ._connectpage(observ.java:159)
    at com.ab.template.observ._websocket_connected(observ.java:424)
    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.shell.Shell.runMethod(Shell.java:632)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:237)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
    at jdk.internal.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
    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:91)
    at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:78)
    at anywheresoftware.b4j.object.WebSocketModule$Adapter$ThreadHandler.run(WebSocketModule.java:188)
    at anywheresoftware.b4a.keywords.SimpleMessageLoop.runMessageLoop(SimpleMessageLoop.java:30)
    at anywheresoftware.b4a.StandardBA.startMessageLoop(StandardBA.java:26)
    at anywheresoftware.b4a.shell.ShellBA.startMessageLoop(ShellBA.java:119)
    at anywheresoftware.b4a.keywords.Common.StartMessageLoop(Common.java:153)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:309)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
    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:91)
    at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:78)
    at anywheresoftware.b4j.object.JServlet.createInstance(JServlet.java:65)
    at anywheresoftware.b4j.object.BackgroundWorkersManager$1.run(BackgroundWorkersManager.java:21)
Observ06b78092-7e33-4487-b372-c5bef0ca21d6
    at anywheresoftware.b4a.keywords.SimpleMessageLoop.runMessageLoop(SimpleMessageLoop.java:30)
    at anywheresoftware.b4a.StandardBA.startMessageLoop(StandardBA.java:26)
    at anywheresoftware.b4a.shell.ShellBA.startMessageLoop(ShellBA.java:119)
    at anywheresoftware.b4a.keywords.Common.StartMessageLoop(Common.java:153)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:309)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
    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:91)
    at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:78)
    at com.ab.template.main.main(main.java:29)

What am I doing wrong?
 

Rob White

Member
Licensed User
Just looked at the diagrams produced by the Grid generator! all cells are (1,x). I was of the belief the coordinates are (row,column)
Is this correct?

Of course this does not explain my blank pages using co ords (1,1).
 
Upvote 0

Rob White

Member
Licensed User
Don't worry all - Make sure you paste code in correct place!!
Refresh should be after the controls are created!! Off course!
 
Upvote 0

Harris

Expert
Licensed User
Longtime User
page.AddRows(1,True,"").AddCells12(1,"").AddCellsOS(2,0,0,0,6,6,6,"").AddCells12(2,"").AddCellsOS(1,0,0,0,7,7,7,"").AddCellsOS(1,0,0,0,5,5,5,"")

WOW!

Now that's funky... Can this be explained as to what was trying to be accomplished?
 
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
page.AddRows(1,True,"").AddCells12(1,"").AddCellsOS(2,0,0,0,6,6,6,"").AddCells12(2,"").AddCellsOS(1,0,0,0,7,7,7,"").AddCellsOS(1,0,0,0,5,5,5,"")
As you can see in the comments, that is still one row, but the cells > 12 wrap.

So you would need to use page.Cell(1,2).AddComponent(lblTitle) to get to your 'wrapping' second row.

As there can never be more than 12 cells in a row, it will make it easier to write it like this
B4X:
page.AddRows(1,True,"").AddCells12(1,"") ' row 1
page.AddRows(1,True,"").AddCellsOS(2,0,0,0,6,6,6,"") ' row 2
page.AddRows(2,True,"").AddCells12(1,"") ' row 3 and 4
page.AddRows(1,True,"").AddCellsOS(1,0,0,0,7,7,7,"").AddCellsOS(1,0,0,0,5,5,5,"") ' row 5

' now you can use:
page.Cell(2,1).AddComponent(lblTitle)
 
Upvote 0
Top