B4J Question Problem working with JavaFX Scene Builder

LucianoB

Member
Licensed User
Longtime User
Hello Erel, I'm new to JavaFX Scene Builder, I tryed to follow exactly the tutorials but I'm facing to a strange (to me) problem.
I've the following code in the Upload Class from your FileServer, which was Not-UI. I wanted to have an UI so I created a new one with UI and copied and adapted yours.

B4X:
Sub Handle(req As ServletRequest, resp As ServletResponse)
    If req.Method <> "POST" Then
        resp.SendError(500, "method not supported.")
        Return
    End If
    'we need to call req.InputStream before calling GetParameter.
    'Otherwise the stream will be read internally (as the parameter might be in the post body).
    Dim In As InputStream = req.InputStream
    Dim reqType As String = req.GetParameter("type")
    If reqType = "" Then
        resp.SendError(500, "Missing type parameter.")
        Return
    End If
    Select reqType
        Case "text"
            Dim tr As TextReader
            tr.Initialize(In)
            txtUser.Initialize("mio")
            Label1.TextColor = fx.Colors.Black
            'Msgbox.Show (tr.ReadAll,"")
                       
            txtUser.Text = tr.Readall
            'Label1.Text=tr.Readall
            'tr.Initialize(In)
            'Log("Received text message: " & CRLF & tr.ReadAll)
       
            resp.Write("Message received successfully.")
        Case "file"
            Dim name As String = req.GetParameter("name")
            Dim out As OutputStream = File.OpenOutput(Main.filesFolder, name, False)
            File.Copy2(In, out)
            out.Close
            Log("Received file: " & name & ", size=" & File.Size(Main.filesFolder, name))
            resp.Write("File received successfully.")
    End Select
End Sub

I created txtUser and label1 with JavaFX Scene Builder. When I run the server nothing is sent to the txtUser or the Label1 which remain blank. But if I check the Watch pane on the bottom it looks it receives the text sent by the client side app: (TextField) TextField@2ae7a162[styleClass=text-input text-field], Text: mytextsent,.
Any idea on what I missed? thank you
 

LucianoB

Member
Licensed User
Longtime User
It wasn't my intention to give limits to my question. Surely I made a mistake posting it. If I can correct it I will do.

Well, I'm using Scene Builder just because it opened automatically when I hit [Create New Layout] in Designer menu in B4J...

EDIT: if I can use the internal designer please can you tell me how to launch it? thank you
 
Upvote 0

LucianoB

Member
Licensed User
Longtime User
I'm using v2.80. maybe that was the problem. downloading the new version. thank you very much for your great support!
 
Upvote 0

LucianoB

Member
Licensed User
Longtime User
Installed 3.50, used the internal designer but still have the same problem. I know that maybe I'm doing a conceptual mistake.
I added a Textfield named txtUser via internal designer.
NOT used "txtUser.Initialize("mio")" because it should be initialized when the layout loads.
But if I don't use it the log says:java.lang.RuntimeException: Object should first be initialized (TextField).
The txtUser.text is set in the Upload class, not in the Main.
mmm I feel so silly asking that :)
 
Upvote 0

LucianoB

Member
Licensed User
Longtime User
Just fyi.
I fixed the problem in this way.

In the Class module 'Upload' I added a row

B4X:
Sub Handle(req As ServletRequest, resp As ServletResponse)
    If req.Method <> "POST" Then
        resp.SendError(500, "method not supported.")
        Return
    End If
    'we need to call req.InputStream before calling GetParameter.
    'Otherwise the stream will be read internally (as the parameter might be in the post body).
    Dim In As InputStream = req.InputStream
    Dim reqType As String = req.GetParameter("type")
    If reqType = "" Then
        resp.SendError(500, "Missing type parameter.")
        Return
    End If
    Select reqType
        Case "text"
            Dim tr As TextReader
            tr.Initialize(In)
            'txtUser.Initialize("txtUser")
            'Label1.TextColor = fx.Colors.Black
            'Msgbox.Show (tr.ReadAll,"")
            Main.test1(tr.ReadAll )       <==========ADDED THIS ROW
            'txtUser.Text = tr.Readall
            'Label1.Text= "ciao" 'tr.Readall
            'tr.Initialize(In)
            'Log("Received text message: " & CRLF & tr.ReadAll)
       
            resp.Write("Message received successfully.")
        Case "file"
            Dim name As String = req.GetParameter("name")
            Dim out As OutputStream = File.OpenOutput(Main.filesFolder, name, False)
            File.Copy2(In, out)
            out.Close
            Log("Received file: " & name & ", size=" & File.Size(Main.filesFolder, name))
            resp.Write("File received successfully.")
    End Select
End Sub

In the Main added this Sub

B4X:
Sub test1(txt As String)
txtUser.text = txt
End Sub

and now it works. The txtUser textfield receives the text from the Android client.
Don't know if it's the right way but it's simple and works.
 
Upvote 0
Top