B4J Question ABMATERIAL Live or Cached - data Access (urgent please)

codie01

Active Member
Licensed User
Longtime User
Good Day All,

Tomorrow I need to demo my app and website to my Boss. I thought all ways going well until I got the desktop app going today.

My problem is, that in the Tab part of my page, under "Products" I have chips that are made by reading the Product group table and generating chips on the fly. see website: http://104.238.77.163:51042/ds/ds_home/

I thought all was fine until I started adding groups on the desktop version, both connected to the same database.

The chips are not updating after a refresh, what appears to be the problem is either:

1. Cache (cleared it and the problem remains)
2. During compiling the compiler reads the chips in and compiles the jar fixed.

If I recompile and load the website again, the website displays correctly until I add a new group or change the text on a group.

Code shown here.

B4X:
      Dim ch1 As ABMChip
      ch1.Initialize(page, "Products Page", "Products Page", False, "")
      Tabc.Cell(2,1).AddArrayComponent(ch1, "catagories")
      'Tabc.Cell(2,2).AddComponent(ABMShared.BuildParagraphHeader(page, "par1", "Select a product catagory below"))
      ' Read Product Group Table       
      Dim cursor As ResultSet
      Try
            cursor = sql1.ExecQuery("SELECT s_productgroup FROM qualas_productgroup")
            Dim myCell As Int = 2
          Do While cursor.NextRow
                ' Read Single record from productgroup table
                Dim vRow(1) As Object
                vRow(0) = cursor.GetString("s_productgroup")
               Dim ch1 As ABMChip
                  ch1.Initialize(page, vRow(0), vRow(0), False, "chiptheme")
                  Tabc.Cell(3,2).AddArrayComponent(ch1, "catagories")
                myCell = myCell +1
           Loop
        Catch
           Log("ERROR: " & LastException.Message)
        End Try

Ideas please.

Regards Phil
 

Harris

Expert
Licensed User
Longtime User
I don't see where you are calling ch1.refresh? Should be after loop, or after I have found (with tables), in the Page Ready event.

or

page.Row(number).refresh... (most likely)

or

the Tabc.Cell(3,2) needs to be refeshed since your array of chips are going in there...

Site looks nice... Wish I was in NZ, fly fishing for some huge rainbows...
 
Last edited:
Upvote 0

codie01

Active Member
Licensed User
Longtime User
Thanks Harris,

Come over one day, trout fishing on Saturday if I get this done. I have now tracked my fault, it is a database connection issue.

On Localhost, when I compile the server starts with no issues. When connect the browser and/or refresh it logs:

Disconnected
java.lang.NullPointerException
at anywheresoftware.b4j.object.WebSocketModule$Adapter.onWebSocketText(WebSocketModule.java:121)
at org.eclipse.jetty.websocket.common.events.JettyListenerEventDriver.onTextMessage(JettyListenerEventDriver.java:127)
at org.eclipse.jetty.websocket.common.message.SimpleTextMessage.messageComplete(SimpleTextMessage.java:69)
at org.eclipse.jetty.websocket.common.events.AbstractEventDriver.appendMessage(AbstractEventDriver.java:64)
at org.eclipse.jetty.websocket.common.events.JettyListenerEventDriver.onTextFrame(JettyListenerEventDriver.java:121)
at org.eclipse.jetty.websocket.common.events.AbstractEventDriver.incomingFrame(AbstractEventDriver.java:169)
at org.eclipse.jetty.websocket.common.WebSocketSession.incomingFrame(WebSocketSession.java:302)
at org.eclipse.jetty.websocket.common.extensions.ExtensionStack.incomingFrame(ExtensionStack.java:210)
at org.eclipse.jetty.websocket.common.Parser.notifyFrame(Parser.java:219)
at org.eclipse.jetty.websocket.common.Parser.parse(Parser.java:257)
at org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection.read(AbstractWebSocketConnection.java:500)
at org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection.onFillable(AbstractWebSocketConnection.java:409)
at org.eclipse.jetty.io.AbstractConnection$1.run(AbstractConnection.java:534)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:607)
at org.eclipse.jetty.util.thread.QueuedThreadPool$1.run(QueuedThreadPool.java:536)
at java.lang.Thread.run(Thread.java:745)
Connected


If I take out the following code the problem disappears.

Can someone steer me in the right direction. In the MAIN I have as Follows:

B4X:
'Non-UI application (console / server application)
#Region  Project Attributes
    #CommandLineArgs:
    #MergeLibraries: True
#End Region

Sub Process_Globals
    Public srvr As Server 
    #AdditionalJar: mysql-connector-java-5.1.36-bin.jar
    Public sql1 As SQL
End Sub

Sub AppStart (Args() As String)
    ' Build the Theme
    ABMShared.BuildTheme("mytheme")
 
    ' create the app
    Dim myApp As ABMApplication
    myApp.Initialize
     
    ' create the pages
 
    Dim myPage As ds_home
    myPage.Initialize 
 
    ' add the pages to the app
    myApp.AddPage(myPage.Page)
 
    ' start the server
    myApp.StartServer(srvr, "srvr", 51042) 
 
    StartMessageLoop
End Sub

Then in myfirstpage I have some cells being loaded as follows:

B4X:
      Try
            Dim sql1 As SQL
            sql1.Initialize2("com.mysql.jdbc.Driver", "jdbc:mysql://104.238.77.163/mydatabse", "myuser", "mypassword)(*&")
            cursor = sql1.ExecQuery("SELECT * FROM qualas_productgroup")
            Dim myCell As Int = 2
          Do While cursor.NextRow
                ' Read Single record from productgroup table
                Dim vRow(1) As Object
                vRow(0) = cursor.GetString("s_productgroup")
               Dim catg As ABMChip
                  catg.Initialize(page, vRow(0), vRow(0), True, "chiptheme")
                'catg.Refresh
                  Tabc.Cell(3,2).AddArrayComponent(catg, "catagories")
                myCell = myCell +1
           Loop
            sql1.Close
        Catch
           Log("ERROR: " & LastException.Message)
        End Try
      'Tabc.Cell(3,1).AddComponent(ABMShared.BuildParagraphHeader(page, "par1", "{NBSP}"))
    End If

I think I have all this is the wrong place. Thanks in advance.

Phil
 
Last edited:
Upvote 0

Harris

Expert
Licensed User
Longtime User
I see your NOT using the pool for DB connections... This will limit how many concurrent connections you will be able to have.

You need to ask @alwaysbusy for a link to the source for the Feedback app.
I have learned a great deal from it.

I have not used chips or tabs yet so I can't help you there.
Should't be much different handling them than any other component however.
 
Upvote 0

codie01

Active Member
Licensed User
Longtime User
Hi Harris,

Well after 3 hours work I have successfully intergrated database access. No errors when the browser starts no issues when the page is refresh EXCEPT :( The Chips do not update so I placed a log in the code below and to my delight the returned info from the database changes when my desktop software changes them.

B4X:
      ' open and read from product file
      Dim SQL As SQL = DBM.GetSQL
      Dim productgroups As List = DBM.SQLSelect(SQL, "SELECT * FROM qualas_productgroup")
      If productgroups.Size > 0 Then
           Log(productgroups.size)
      End If
      DBM.CloseSQL(SQL)       

      For i = 0 To productgroups.Size-1
            Dim tblFields As Map = productgroups.Get(i)
            Dim catg As ABMChip
          Dim a As String = tblFields.GetValueAt(0)
          Log(a) 'Shows changes as they happen and browser is refreshed
          catg.Initialize(page, a, a, False, "")
          Tabc.Cell(3,1).AddComponent(catg)
      Next

Great now all I have to do is insert catg.Refresh after next or Tab.Cell(3,1). Refresh or maybe a page.Refresh, all to no avail. In fact anything with .Refresh will cause the following error.


init mysql
Jan 08, 2016 5:28:16 PM com.mchange.v2.log.MLog <clinit>
INFO: MLog clients using java 1.4+ standard logging.
Jan 08, 2016 5:28:16 PM com.mchange.v2.c3p0.C3P0Registry banner
INFO: Initializing c3p0-0.9.2.1 [built 20-March-2013 11:16:28 +0000; debug? true; trace: 10]
Jan 08, 2016 5:28:16 PM com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource getPoolManager
INFO: Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 20000, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, dataSourceName -> 1hgf02h9e8qkdv2mrbikb|4f2410ac, debugUnreturnedConnectionStackTraces -> false, description ->...
6
Quick Systems

ds_home._buildtabcontainer (java line: 192)
java.lang.NullPointerException
at com.ab.abmaterial.ABMCell.Refresh(Unknown Source)

at b4j.example.ds_home._buildtabcontainer(ds_home.java:192)
at b4j.example.ds_home._buildpage(ds_home.java:85)
at b4j.example.ds_home._initialize(ds_home.java:245)
at b4j.example.main._appstart(main.java:57)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
at b4j.example.main.main(main.java:29)


Any Ideas. Thanks in Advance
 
Upvote 0

Harris

Expert
Licensed User
Longtime User
Like I stated earlier, I think you may need a Page.Row(row_num).refresh...

You are adding these chips to a row...
Tabc.Cell(3,1).AddComponent(catg) - row 3 cell 1...

So at the end of the loop (next), do a row refresh...
ie.
next
page.Row(3).Refresh '(hell - you tried everything else but!)

As a quick example, here is my Page_Ready() event..

B4X:
Sub Page_Ready()
    Log("ready!")
    page.RestoreNavigationBarPosition

    ' refresh elements that may be not visible or may need refreshing due to new items added...   
    page.Footer.Cell(2,1).Refresh
    page.Row(1).Refresh   
    LoadCases(1)

End Sub

Hey, don't dispare. I am stuck in the same rut trying to figure this all out (but getting there).
Like I said in an earlier post (somewhere) - it's the same - only different...
In essence, we are writing HTML and .js code when we use ABMaterial (that's the compiled output - an "index.html" and "page".js" (some .css as well) for each page we create). This is the "different" part.

I am slowly getting past the learning curve and discovering what really works, what are bugs and what my wishes are and what I KNOW NOTHING ABOUT!

Between his day job and what he can steal after work until he wakes to resume his day job, @alwaysbusy is progressively building a fantastic framework.

Pretty soon, you will be providing tutorials based on your expert knowledge, and your experience of how it was accomplished that will contribute to us all.

Lastly, IMHO, this is a F*&% of alot better than writing HTML, JS, PHP, JQuery, ASP, AJAX, and you name it to accomplish the EXACT same task!!!!
Although it may lack some current functionality, I am confident that the community will embrace this and grow it into a (B4J) Material defacto standard.

Thanks
 
Upvote 0

codie01

Active Member
Licensed User
Longtime User
Hi Harris,

Thanks mate. I have now stripped my page down to just a single row and then build the grid. After building the grid I add page.refresh and get the same error. Remove the grid and leave page.refresh on its own and there is no issues or error.

B4X:
public Sub BuildPage()
    ' initialize the theme
    BuildTheme
   
    ' initialize this page using our theme
    page.InitializeWithTheme(Name, "/ws/" & AppName & "/" & Name, False, theme)
    page.ShowLoader=True
       
    ' adding a navigation bar
    ' ABMShared.BuildNavigationBar(page, " ","", "", "", "ds_home")
   
    ' add the header
    ' ABMShared.BuildPageHeader(page)
   
    ' build grid
    '-------------------------- take this section out, refreshes fine -------------------------------
    page.AddRows(1, False,"").AddCells12(12, "")
    page.BuildGrid
   
    page.Cell(1,1).AddComponent(ABMShared.BuildParagraph(page, "par1", "Why Hello"))
   
    '--------------------------------------------------------------------------------------------------
    page.Cell(1,1).Refresh ' or swith to page.Refresh
   
   
End Sub

I have downloaded the latest version of B4J. I have downloaded the latest jdk as specified by B4J

I have changed to all the backups of ABMaterial versions and no it does not work. I have checked all the loaded Libraries. You seem to issues refreshes as you wish yet I can not issue a single one.


Time to depart from this and go back to a standard website and php. I'm sure it will be awesome when it gets there, I've simply lost a week and need an urgent solution, yet I think it still rocks and the idea is awesome.

Regards Phil
 
Last edited:
Upvote 0

Harris

Expert
Licensed User
Longtime User
I only call a refresh AFTER the page is ready. I know doing so prior to this will raise an error.
After the event is raised, Page_Ready(), you can refresh in other subs...

Good luck...
 
Upvote 0
Top