B4J Question WebApp Click Event called twice

Eumel

Active Member
Licensed User
Longtime User
Hi..

https://www.dropbox.com/s/uk3yko39g7lg54s/dp_example.zip

This is a small program i´m writing.
It´s a Web App with sqlite

To login use:

Username: dummy
Passwort: pass

Even if i save a new record, the click event is called again, and i get error
B4X:
Online: dummy
Error occurred on line: 42 (dienstneu).
java.lang.RuntimeException: org.eclipse.jetty.websocket.api.WebSocketException: RemoteEndpoint unavailable, current state [CLOSED], expecting [OPEN or CONNECTED]
  at anywheresoftware.b4j.object.WebSocket.get(WebSocket.java:120)
  at anywheresoftware.b4j.object.WebSocket.access$1(WebSocket.java:110)
  at anywheresoftware.b4j.object.WebSocket$JQueryElement.RunMethodWithResult(WebSocket.java:207)
  at anywheresoftware.b4j.object.WebSocket$JQueryElement.GetVal(WebSocket.java:228)
  at b4j.dp.example.dienstneu._btnspeichern_click(dienstneu.java:97)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:606)
  at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:563)
  at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:221)
  at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:156)
  at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:606)
  at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
  at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:82)
  at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
  at anywheresoftware.b4j.object.WebSocketModule$Adapter$1.run(WebSocketModule.java:127)
  at anywheresoftware.b4a.keywords.SimpleMessageLoop.runMessageLoop(SimpleMessageLoop.java:30)
  at anywheresoftware.b4a.StandardBA.startMessageLoop(StandardBA.java:26)
  at anywheresoftware.b4a.ShellBA.startMessageLoop(ShellBA.java:103)
  at anywheresoftware.b4a.keywords.Common.StartMessageLoop(Common.java:131)
  at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:292)
  at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:156)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:606)
  at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
  at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:82)
  at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
  at b4j.dp.example.main.main(main.java:28)
Caused by: org.eclipse.jetty.websocket.api.WebSocketException: RemoteEndpoint unavailable, current state [CLOSED], expecting [OPEN or CONNECTED]
  at org.eclipse.jetty.websocket.common.WebSocketSession.getRemote(WebSocketSession.java:245)
  at anywheresoftware.b4j.object.WebSocket.sendText(WebSocket.java:107)
  at anywheresoftware.b4j.object.WebSocket.get(WebSocket.java:117)
  ... 32 more

Line 42 (dienstneu) catch the value of the textfield and the first call works fine.
All saved in database, after that it should redirect to dienst_liste.html.
This site is show, but the program runs again in module "Dienstneu" and calls the click.

I searched but don´t found what´s wrong.
Anybody can help ?



Thx
Eumel
 

Kiffi

Well-Known Member
Licensed User
Longtime User
Hello Eumel,

for some reasons you have two websocket-connections (see screenshot). Two connections means: two setAutomaticEvents. So the click-event is fired twice.

Greetings ... Peter
 

Attachments

  • 2014-05-09_185058.png
    2014-05-09_185058.png
    17.4 KB · Views: 225
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. You should always use parameterized queries:
B4X:
"SELECT * FROM user WHERE name='"&nUser&"'"
Even if you escape the string. It is simpler:
B4X:
DBUtils.ExecuteMap(Main.sql_user,"SELECT * FROM user WHERE name= ?" ,Array As String(nUser)) '100% safe from SQL injection

2. You shouldn't write JQueryElement.GetVal.Value (unless you are planning to run your web app in the local network). Read the network latency section here: http://www.b4x.com/android/forum/threads/webapp-hello-world-web-app.39808/#content

3. Something in your page causes the Ready event to fire twice. Move this script to the end of the head node:
B4X:
<script>
  $( document ).ready(function() {
     alert("a");
  b4j_connect("/member/dienstneu/ws");
  
  });
   </script>
</head>
 
Upvote 0

Eumel

Active Member
Licensed User
Longtime User
What, it was so easy ? I´m ashamed now :oops:
Thx billzhan.

Thx Erel for the suggestion. Sometimes a kick refreshes the brain :D


Greetings
Eumel
 
Upvote 0

billzhan

Active Member
Licensed User
Longtime User
Forget to mention, the chartset in the html files are "utf8" so you have to save html files in utf8 encoding. Otherwise, the pages will not be shown correctly on some circumstances.
 
Upvote 0
Top