Ваадин с базой данных Firebase RealtimeJAVA

Программисты JAVA общаются здесь
Ответить Пред. темаСлед. тема
Anonymous
 Ваадин с базой данных Firebase Realtime

Сообщение Anonymous »


I'm trying to show a notification for extracted data. For some reason the data is successfully extracted but the notification is not shown. Mind you the notification is shown when not inside the onDataChange method.

` public HomeNew() { VerticalLayout verticalLayout = new VerticalLayout(); verticalLayout.setSizeFull(); verticalLayout.setWidthFull(); button = new Button("TestBUTTON"); button.addClickListener(new ComponentEventListener() { @Override public void onComponentEvent(ClickEvent buttonClickEvent) { UI.getCurrent().access(() -> { Notification extractedDataNotification = Notification .show("Extracted Data: " + "data"); extractedDataNotification.addThemeVariants(NotificationVariant.LUMO_SUCCESS); }); DatabaseReference database = FirebaseDatabase.getInstance().getReference(); database.addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { // Extract data from Firebase String data = dataSnapshot.child("data").getValue(String.class); logger.info("Extracted Data: " + data); } @Override public void onCancelled(DatabaseError databaseError) { // Handle onCancelled event if needed } }); } }); verticalLayout.add(button); add(verticalLayout);` This code works, when the notification is outside of onDataChange.

`public HomeNew() { VerticalLayout verticalLayout = new VerticalLayout(); verticalLayout.setSizeFull(); verticalLayout.setWidthFull(); button = new Button("TestBUTTON"); button.addClickListener(new ComponentEventListener() { @Override public void onComponentEvent(ClickEvent buttonClickEvent) { DatabaseReference database = FirebaseDatabase.getInstance().getReference(); database.addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { // Extract data from Firebase String data = dataSnapshot.child("data").getValue(String.class); logger.info("Extracted Data: " + data); UI.getCurrent().access(() -> { Notification extractedDataNotification = Notification .show("Extracted Data: " + data); extractedDataNotification.addThemeVariants(NotificationVariant.LUMO_SUCCESS); }); } @Override public void onCancelled(DatabaseError databaseError) { // Handle onCancelled event if needed } }); } }); verticalLayout.add(button); add(verticalLayout);` This one doesn't work when the notification is inside the onDataChange method, which is what I need.Also the logs indicate the data is being extracted succesfully. 2024-03-02T21:41:55.703+03:00 INFO 13072 --- [se-event-target] com.example.application.views.Database : Extracted Data: Hello this is data

Some logs. I am also initializing firebase with a different section of code not included. `

| / |_ _ / \ _ __ _ __
| |/| | | | | / _ \ | '_ | '_ \ | | | | || | / ___ | |) | |) | || ||_, | // _\ ./| ./ |__/ || ||

2024-03-02T21:41:23.660+03:00 INFO 13072 --- [ restartedMain] com.example.application.Application : Starting Application using Java 21.0.1 with PID 13072 (C:\Users\Admin\Desktop\Projects\new app\my-app\target\classes started by Admin in C:\Users\Admin\Desktop\Projects\new app\my-app) 2024-03-02T21:41:23.678+03:00 INFO 13072 --- [ restartedMain] com.example.application.Application : No active profile set, falling back to 1 default profile: "default" 2024-03-02T21:41:23.892+03:00 INFO 13072 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable 2024-03-02T21:41:23.893+03:00 INFO 13072 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG' 2024-03-02T21:41:28.417+03:00 INFO 13072 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port 8080 (http) 2024-03-02T21:41:28.449+03:00 INFO 13072 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2024-03-02T21:41:28.450+03:00 INFO 13072 --- [ restartedMain] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/10.1.18] 2024-03-02T21:41:28.683+03:00 INFO 13072 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2024-03-02T21:41:28.686+03:00 INFO 13072 --- [ restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 4788 ms Standard Commons Logging discovery in action with spring-jcl: please remove commons-logging.jar from classpath in order to avoid potential conflicts 2024-03-02T21:41:28.710+03:00 WARN 13072 --- [ restartedMain] c.v.f.s.VaadinServletContextInitializer : vaadin.whitelisted-packages is deprecated and may not be supported in the future. Use vaadin.allowed-packages instead. 2024-03-02T21:41:31.166+03:00 INFO 13072 --- [ restartedMain] c.v.f.s.VaadinServletContextInitializer : Search for subclasses and classes with annotations took 1862 ms 2024-03-02T21:41:32.942+03:00 INFO 13072 --- [ restartedMain] c.v.b.d.startup.DevModeStartupListener : Starting dev-mode updaters in C:\Users\Admin\Desktop\Projects\new app\my-app folder. 2024-03-02T21:41:33.132+03:00 INFO 13072 --- [ restartedMain] c.v.f.s.f.s.FullDependenciesScanner : Visited 116 classes. Took 131 ms. 2024-03-02T21:41:33.136+03:00 INFO 13072 --- [ restartedMain] c.v.f.s.frontend.BundleValidationUtil : Checking if a development mode bundle build is needed 2024-03-02T21:41:34.189+03:00 INFO 13072 --- [ restartedMain] c.v.f.s.frontend.BundleValidationUtil : A development mode bundle build is not needed 2024-03-02T21:41:34.307+03:00 INFO 13072 --- [onPool-worker-1] c.v.f.s.frontend.TaskCopyFrontendFiles : Copying frontend resources from jar files ... 2024-03-02T21:41:34.615+03:00 INFO 13072 --- [onPool-worker-1] c.v.f.s.frontend.TaskCopyFrontendFiles : Visited 20 resources. Took 309 ms. 2024-03-02T21:41:34.616+03:00 ERROR 13072 --- [ restartedMain] com.example.application.FCMInitializer : class path resource [classpath:serviceaccount.json] cannot be opened because it does not exist 2024-03-02T21:41:36.129+03:00 INFO 13072 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729 2024-03-02T21:41:36.508+03:00 INFO 13072 --- [ restartedMain] c.v.f.s.DefaultDeploymentConfiguration : Vaadin is running in DEVELOPMENT mode - do not use for production deployments. 2024-03-02T21:41:36.685+03:00 INFO 13072 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port 8080 (http) with context path '' 2024-03-02T21:41:36.714+03:00 INFO 13072 --- [ restartedMain] com.example.application.Application : Started Application in 14.489 seconds (process running for 17.618) 2024-03-02T21:41:37.063+03:00 INFO 13072 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet' 2024-03-02T21:41:37.064+03:00 INFO 13072 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet' 2024-03-02T21:41:37.079+03:00 INFO 13072 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 10 ms 2024-03-02T21:41:39.112+03:00 INFO 13072 --- [io-8080-exec-10] c.vaadin.flow.spring.SpringInstantiator : The number of beans implementing 'I18NProvider' is 0. Cannot use Spring beans for I18N, falling back to the default behavior 2024-03-02T21:41:49.667+03:00 INFO 13072 --- [nio-8080-exec-6] com.example.application.views.Database : Firebase application has been initialized successfully 2024-03-02T21:41:55.703+03:00 INFO 13072 --- [se-event-target] com.example.application.views.Database : Extracted Data: Hello this is data `


Источник: https://stackoverflow.com/questions/780 ... e-database
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение
  • Проблема с базой данных Firebase Realtime. Состояние гонки с Android Java.
    Anonymous » » в форуме JAVA
    0 Ответы
    16 Просмотры
    Последнее сообщение Anonymous
  • Проблема с базой данных Firebase Realtime. Состояние гонки с Android Java.
    Anonymous » » в форуме Android
    0 Ответы
    12 Просмотры
    Последнее сообщение Anonymous
  • Проблема с базой данных Firebase Realtime. Состояние гонки с Android Java.
    Anonymous » » в форуме JAVA
    0 Ответы
    13 Просмотры
    Последнее сообщение Anonymous
  • Проблема с базой данных Firebase Realtime. Состояние гонки с Android Java.
    Anonymous » » в форуме Android
    0 Ответы
    9 Просмотры
    Последнее сообщение Anonymous
  • Соединение с базой данных Firebase Realtime разорвано: другой регион
    Anonymous » » в форуме Android
    0 Ответы
    15 Просмотры
    Последнее сообщение Anonymous

Вернуться в «JAVA»