B4J Question [ABMaterial] Referencing components....

Cableguy

Expert
Licensed User
Longtime User
Hi guys,

So, I have a Floating container, id = "floatingcont1". Inside it I have a another container, id = "cont2". Inside it I have a collapsable container, id = "cont3"...

I try to reference "cont3" fom an event with...
B4X:
    Dim collbody As ABMContainer
    collbody = page.Component("cont3")
I also tried...
B4X:
    Dim collbody As ABMContainer
    collbody = page.FloatingContainer("floatingcont1").Component("cont3")

But I always get "No component found with id cont3"

So... please help!!
 

alwaysbusy

Expert
Licensed User
Longtime User
Hard to say without seeing any creation code, but from your description cont3 is in cont2 which is in itself in floatingcont1 so I would try this:

B4X:
Dim FloatingCont1 as ABMContainer = Page.Component("floatingcont1")
Dim Cont2 as ABMContainer = FloatingCont1.Component("cont2")
Dim Cont3 as ABMContainer = cont2.Component("cont3")

At the very least, you may see how deep it does work.
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Hard to say without seeing any creation code, but from your description cont3 is in cont2 which is in itself in floatingcont1 so I would try this:

B4X:
Dim FloatingCont1 as ABMContainer = Page.Component("floatingcont1")
Dim Cont2 as ABMContainer = FloatingCont1.Component("cont2")
Dim Cont3 as ABMContainer = cont2.Component("cont3")

At the very least, you may see how deep it does work.
You assume right... I had a feeling that I needed to drill it down.... was hopping not to have to...
 
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
I had a feeling that I needed to drill it down.... was hopping not to have to
It must be like that. A component in HTML must have a unique ID. So in the html code, ABM takes that in account and builds new IDs from the tree of components you write that guarantee they are unique (if you would look at the html code, the id for cont3 would be something different).

This way, you do not have to worry if somewhere else in your code you re-use e.g. 'cont3' for something completely different. If it didn't work this way and you could use Page.Component("cont3"), then which one did you mean? The first one or the second one? So, you must follow the tree again.

Alwaysbusy
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Ok, so I'm making progress....

"cont3" is a collapsable container, and inside it's header, I have 3 buttons... The idea is to have different bodies, according to which button was clicked...
The button click event will "open" the body, and start a timer, and the timer's tick event will close the body...
I have this...
B4X:
Sub BuildTopNavBar
    ' get the floating container
    Dim TopNavBar As ABMContainer
    TopNavBar = page.FloatingContainer("floatingcont1")
    
    ' create menu container
    Dim cont2 As ABMContainer
    cont2.Initialize(page, "cont2", "menu")
    cont2.AddRows(1,True,"").AddCellsOS(1,0,0,0,3,3,3,"").AddCellsOS(1,3,3,3,6,6,6,"")
    cont2.BuildGrid
    cont2.Cell(1,1).Margintop = "6px"
    cont2.Row(1).marginBottom = "0"

    Dim img As ABMImage
    img.Initialize(page, "img", "../images/Signature.png",1)
    img.SetFixedSize(300,100)
    cont2.Cell(1,1).AddComponent(img)
    
    Dim cont3 As ABMContainer
    cont3.InitializeCollapsable(page, "cont3", "", "", "", False)
    cont3.CollapsableHeading.AddRows(1,False,"").AddCellsOS(4,0,0,0,3,3,3,"")
    cont3.CollapsableHeading.BuildGrid ' IMPORTANT!
    cont3.SetContentIsOpen(True)
    cont2.Cell(1,2).AddComponent(cont3)
    cont3.CollapsableHeading.Row(1).Margintop = "75px"
    cont3.CollapsableHeading.Row(1).marginBottom = "0"

    Dim btn1 As ABMButton
    btn1.InitializeFlat(page, "btn1", "", "", "{B}Activitées{/B}", "topbar")
    btn1.UseFullCellWidth = True
    cont3.CollapsableHeading.Cell(1,1).AddComponent(btn1)
    
    Dim btn2 As ABMButton
    btn2.InitializeFlat(page, "btn2", "", "", "{B}Partenariats{/B}", "topbar")
    btn2.UseFullCellWidth = True
    cont3.CollapsableHeading.cell(1,2).AddComponent(btn2)
    
    Dim btn3 As ABMButton
    btn3.InitializeFlat(page, "btn3", "", "", "{B}Contacts{/B}", "topbar")
    btn3.UseFullCellWidth = True
    cont3.CollapsableHeading.cell(1,3).AddComponent(btn3)
    
    ' add it to the floating container
    TopNavBar.Cell(1,1).AddComponent(cont2)
End Sub

Sub btn1_Clicked(Target As String)
    Dim FloatingCont1 As ABMContainer = page.FloatingContainer("floatingcont1")
    Dim Cont2 As ABMContainer = FloatingCont1.Component("cont2")
    Dim collbody As ABMContainer = Cont2.Component("cont3")
    collbody.CollapsableBody.AddRows(1,True,"").AddCellsOSV(3,0,0,0,4,4,4,ABM.VISIBILITY_HIDE_ALL,"")
    collbody.CollapsableBody.BuildGrid ' IMPORTANT!
    collbody.CollapsableBody.OpenContent

End Sub
and I have "page.showGridInfo = True" ...
The body doesn't show! Any hints??
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
This is prooving more complex than I thought... I will start a new thread for a more complete question.
 
Upvote 0
Top