B4J Question [Webapp] Change Div Text From Mobiles Clients

fabricio

Member
Licensed User
Longtime User
Hi,

Scenario:
1 Webapp and many mobile clients.

I'm starting with Webapp and try change div text from text received from mobile app.


duvida-b4j.png


Content of funcoes:

B4X:
Sub Process_Globals
    
End Sub

Public Sub Modifica(jq As JQueryElement, NovoTexto As String)
    jq.SetText(NovoTexto)
End Sub

Thanks.
 

fabricio

Member
Licensed User
Longtime User
I'm used WebAppHelloWorld as example and add one DIV called divtext and I would like to send a text from mobile devices and this text would be shown in div.

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

Sub Process_Globals
    Public srvr As Server
End Sub

Sub AppStart (Args() As String)
    srvr.Initialize("srvr")
    srvr.AddWebSocket("/ws", "HelloWorld")
    srvr.Port = 51042
    srvr.Start
    StartMessageLoop
End Sub

HelloWorld
B4X:
'WebSocket class
Sub Class_Globals
    Private ws As WebSocket 'ignore
    Private text1, text2, btnCalc, Result, divtext As JQueryElement
End Sub

Public Sub Initialize
End Sub

Private Sub WebSocket_Connected (WebSocket1 As WebSocket)
    Log("Connected")
    ws = WebSocket1
End Sub

Sub btnCalc_Click (Params As Map)
    Dim ft2 As Future = text2.GetVal
    Dim ft1 As Future = text1.GetVal
    If IsNumber(ft1.Value) And IsNumber(ft2.Value) Then
        Result.SetText("Result: " & (ft1.Value + ft2.Value))
    Else
        Result.SetText("Invalid numbers")
    End If
End Sub

Private Sub WebSocket_Disconnected
    Log("Disconnected")
End Sub

Sub Device_Message(Params As Map)
    Dim ReceivedMsg As String = Params.Get("message")
    Log(ReceivedMsg)
    'CallSubDelayed3(funcoes, "Modifica", divtext, "teste2")
    divtext.RunMethod("text", Array As Object("teste"))
End Sub

funcoes
B4X:
Sub Process_Globals
    
End Sub

Public Sub Modifica(jq As JQueryElement, NovoTexto As String)
    jq.SetText(NovoTexto)
End Sub
 
Upvote 0

fabricio

Member
Licensed User
Longtime User
No.
Mobile: App made with B4A.
Webapp: Browser on PC.

I receive information from app android, it's OK.
update information from app android on webbrowser is not working.

Thanks
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0
Top