B4J Question [ABMaterial] Use session data before page is send to user?

MathiasM

Active Member
Licensed User
Hello

I want to show some session related data to the user.
I tried to do this in the Buildpage method this way:
B4X:
Dim lblUserID As ABMLAbel
lblUserID.Initialize(page, "lblUserID", page.ws.Session.GetAttribute("userid"), ABM.SIZE_H1, False, "")
page.Cell(1,1).AddComponent(lblUserID)

However, this won't work, as page.ws.Session returns a Null in this stage of the ABM page loading process.

I fixed it by creating an empty label, and in the Websocket_Connected event I put:
B4X:
Dim lblUserID As ABMLabel = page.Component("lblUserID")
lblUserID.Text = page.ws.Session.GetAttribute("userid")
lblUserID.Refresh

This works fine, except that a user sees a empty webpage for half a second, and then the data is injected onto the page. Expected, but I don't think that's a very elegant solution. Is there a way to get session data before the page is send to the user?

If this is impossible, is there a way to show some kind of loading animation while the webpage is still busy connecting to the websocket?

Thanks for any help provided.
 
Solution
Hello

I want to show some session related data to the user.
I tried to do this in the Buildpage method this way:
B4X:
Dim lblUserID As ABMLAbel
lblUserID.Initialize(page, "lblUserID", page.ws.Session.GetAttribute("userid"), ABM.SIZE_H1, False, "")
page.Cell(1,1).AddComponent(lblUserID)

However, this won't work, as page.ws.Session returns a Null in this stage of the ABM page loading process.

I fixed it by creating an empty label, and in the Websocket_Connected event I put:
B4X:
Dim lblUserID As ABMLabel = page.Component("lblUserID")
lblUserID.Text = page.ws.Session.GetAttribute("userid")
lblUserID.Refresh

This works fine, except that a user sees a empty webpage for half a second, and then the data is injected onto the page...

Harris

Expert
Licensed User
Longtime User
Hello

I want to show some session related data to the user.
I tried to do this in the Buildpage method this way:
B4X:
Dim lblUserID As ABMLAbel
lblUserID.Initialize(page, "lblUserID", page.ws.Session.GetAttribute("userid"), ABM.SIZE_H1, False, "")
page.Cell(1,1).AddComponent(lblUserID)

However, this won't work, as page.ws.Session returns a Null in this stage of the ABM page loading process.

I fixed it by creating an empty label, and in the Websocket_Connected event I put:
B4X:
Dim lblUserID As ABMLabel = page.Component("lblUserID")
lblUserID.Text = page.ws.Session.GetAttribute("userid")
lblUserID.Refresh

This works fine, except that a user sees a empty webpage for half a second, and then the data is injected onto the page. Expected, but I don't think that's a very elegant solution. Is there a way to get session data before the page is send to the user?

If this is impossible, is there a way to show some kind of loading animation while the webpage is still busy connecting to the websocket?

Thanks for any help provided.
Put the label build in the ConnectPage() - not the BuildPage() ...
BuildPage happens before the Websocket is connected.
 
Upvote 0
Solution
Top