B4J Question [ABMaterial] B4JS - cannot get it running

OliverA

Expert
Licensed User
Longtime User
The demo for B4JS works. But when I try to use B4JS, I just get a spinning circle and the Browser's console shows:
ReferenceError: b4js_b4jstest is not defined TestPage.1561057241703.js:21:113
<anonymous> http://localhost:51122/Demo/TestPage/TestPage.1561057241703.js:21
b4jstest is the B4JS class module I created.
Steps I performed:
Copy ABMaterial's Template and rename main file.
Add TestPage ABM Web Page class module. In BuildPage, create the following grid
B4X:
page.AddRowsM(1,True,20,0, "").AddCells12MP(1,0,0,0,0,"")
In ConnectPage, add the following code
B4X:
   Dim btnTest As ABMButton
   btnTest.InitializeFlat(page, "btnTest", "", "", "Test Button", "")
   btnTest.B4JSUniqueKey = "myb4jsid"
   btnTest.B4JSOnClick("B4JSTest", "toast", Null)
   page.Cell(1,1).AddComponent(btnTest)
Add B$JSTest ABM B4JS class module with following content
B4X:
'Class module
Sub Class_Globals
   ' use Public or Dim if you want to share this variable over ALL B4JS classes
   ' use Private if only within this class
   Public ABM As ABMaterial 'ignore, just to access the constants   
   Public Page As ABMPage 'ignore, just to be able to run ABMPage B4JS functions   
   
   
End Sub

'Initializes the object. You can NOT add parameters to this method.
'MUST be called InitializeB4JS is automatically called when using this class
Public Sub InitializeB4JS
   
End Sub

public Sub toast()
   Page.B4JSShowToast("1", "", "Hello World", 3000, False)
End Sub
#if JAVASCRIPT

#End If
Run ABM application in either Debug or Release mode and get unending spinning circle with the error message show above in the console log.
If I comment out these two lines
B4X:
'btnTest.B4JSUniqueKey = "myb4jsid"
'btnTest.B4JSOnClick("B4JSTest", "toast", Null)
in TestPage's ConnectPage method, the ABM application runs (and displays the lonely button).

B4J version: 7.32
ABMaterial version: 4.51
Java: 8v212 and 11

I'm attaching the files that are different/new from the standard ABM Template. I've got a feeling that it is something silly on my end, I just can't see/find it.
 

Attachments

  • B4JSTest.zip
    8.6 KB · Views: 389

Harris

Expert
Licensed User
Longtime User
What does the inspect / console of the browser say what's missing?
It should state missing resources.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Upvote 0

OliverA

Expert
Licensed User
Longtime User
The console also has this error message (just before the not defined error in post #1)
SyntaxError: unexpected token: ':' b4js.1561083826945.js:536:20
and going to that line in that file there is
B4X:
     swaloptions.rtl: _b4jsthemes["msgbox-" + ThemeName].RightToLeft;
Looking at the lines above that and below, I think the : should be a =, but that is generated code, not my code. I changed it to a = and now I have a running example. But why did the demo run? Hm...
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Looking at the demo's b4js.xxxxxx.js file, that line does not exist (the swaloptions.rtl). So I did a Tools->Clean project on the Demo and now it has a spinning circle and it now has the same issue on the same line. So something is going on with the code generation for B4JS.
 
Upvote 0
Top