Reputation: 39
Me question related to using Spring Boot with FTL (Freemarker) templates. Is there any way to update my page dynamically? For example: I have one general list for two accounts. When the second user change that list, I want to see those changes on my page without page reloading. Is there any way to realize that? I know that React has this possibility, but I have a lot of code with ftl templates. Will be glad for any answer
Upvotes: 0
Views: 1189
Reputation: 684
without page reloading
That's going to be Ajax operation (if you're after the basic solution).
$.post
to your service/controller, get the response value or JSON object and apply it to page using javascript ot jQuery commands.Ajax and jQuery works nicely inside ftl templates.
Please provide more context and how your data is being served to page, either myself or another member could be able to provide a code sample.
Upvotes: 0
Reputation: 1172
FreeMarker generates static HTML output and nothing more.
In a website the only way to do what you are asking for (change page content without reloading) is to use JavaScript (React also uses JavaScript underneath).
You could detect when someone changed something (eg user list) using WebSocket, long-polling, etc.
Baeldung's intro to WebSocket with Spring
Ps.: You will probably have to repeat some printing logic using JavaScript, for example
Upvotes: 2