Spring and eclipseLink refresh? - java

So I am doing a Java web project using Spring as ORM and eclipse link.
The problem I am having is that after I insert, delete or update data in my database through my web application, the data is refreshed in the mySQL database, but when I go back to my view page the new data isn't there so I have to restart my whole program for the new data to be displayed.
How can I refresh my web application to display the newly inserted, updated, or deleted data without having to restart my whole program?

You aren't saying what front end tech you are using. Angular, React, jQuery?
With a library like Angular you just bind an array representing the data to the view. When you update the array the view auto updates.
You would typically update the array on a success response from the server. So, for example, on a 201 (created), in the promise callback (the .then block) you would update the array with the newly added data. Updating the bound array will update the view.
With libraries like jQuery there is no binding to the view. Instead, you would update the array and then update the HTML dynamically via JavaScript. This would typically be done in an AJAX request callback. See the jQuery.ajax method.

Related

Filtering a Web Service Data Control in JDeveloper

I have a web service data control in JDeveloper 12.2.1.3.0 which I show in a table on a page fragment, but I need to filter by one of the attributes and show the filtered data in the table and I don't know how to do that because there is no Named Criteria tab in the data control configuration page.
I looked at the data control configuration file but didn't find any option for adding a filter.
Any help will be really appreciate it, thank you all in advance!
One solution is to call or implement a web service, that returns the data already sorted and/or filtered.
If this can't be done, you have to get the data from the web service in a POJO model and filter/sort it yourself.

how can i keep backend Data synced with my fronted

I have a "user" class which contains a status attribute, I want to display this attribute in a dashboard.
when the backend changes this attribute I want the frondEnd to display the new value directly without reloading the page .
I use Spring and React
You can use a pub-sub mechanism to achieve this. for example, a kafka topic can be used to sync your changes with the front end.
while inserting a record in your backend DB, push a message to user-kafka-topic.
add a user-kafka-consumer in your front-end application. It would consume messages from the user-kafka-topic at runtime.
you can plan to add you own front-end DB and update the front-end DB.
use observer pattern in your frontend to to update your UI as soon as your json data for the page changes.

Is it possible to refresh all clients with a new thymeleaf model?

I need the front end to display the most recent record in my db (mysql if it makes a difference). Is there a way for my java app to send that value in the thymeleaf model to all existing sessions?
The only way I can think of is to send an ajax request every second to an endpoint that will respond with whether it needs to update or not but this seems a bit hacky

how to update values automatically from database

i am doing mvc project and i want to update the web page automatically when the web page is loaded.
Ex: web page 1 is used to add the companies in database,web page 2 is used to delete the companies,when the web page 2 is loaded automatically in the web page 2 select box should appear with the values as company names to delete the companies from database.
i am expecting to use ajax here to automatically load the data but problem is to fetch the data from database i am using java class instead of jsp or servlet,so i am not understanding how to fetch the data from java class and use to load automatically in web page 2 for the select box.
Please help me on the same.
In this scenario, you have to use servlet, with which ajax will interact to fetch the values on page2. In servlet, you can call you java class to make database connection. Hope it helps!

auto reload content of a postgreSQL table

I am using this code:
my code
to output my table. My question is how is possible to updating it in the page without reloading?
Thank you
Either use AJAX requests or if you feel good, try HTML5 websockets : add a trigger to the table UPDATE / INSERT / DELETE, and keep your clients up-to-date.
AJAX means you'll be doing a request from client to server every few seconds, to check if anything have changed and if so, you'll download the new data (usually devs use JSON), and update your table using javascript with this data.
With websockets, the event starts server side : whenever the db table is updated, you send a request from the server to the clients to tell them to update the table with the new data.
You'll find plenty of examples on the web, searching either for AJAX or websockets.
If you don't know what they are, I'd recommend you to go for AJAX, as setting-up a websockets server with PHP might be tricky.

Categories

Resources