So, I'm trying to constantly display the contents of an object in an HTML page. I'm passing a model through my controller to a form in thymeleaf:
<form id="formTest" class="form-inline" action="#" th:action="@{'log/'}" th:object="${log}" method="post">
...
</form>
This way I can create an object and then print its contents:
<p th:utext="${log.content}" id="IdTest">Log content</p>
The problem is that the content of the object is only displayed when the page is loaded and the first iteration of the function.
Function:
function atualizar() {
var div = $('#logDiv'); // Aponta pra div
var log = $("#atlzr"); // Aponta pro log
var form = $("#formTest");
console.log("Objeto: " + log);
console.log("Conteudo: \n" + log.text());
div.text(log.text());
}
setInterval(function() {atualizar();}, 2000); // Atualiza a cada 2 seg.
Example:
0ºpaginacarregou:<pth:utext="${log.content}" </p>.
1º iteração: <p th:utext="${log.content}" </p>.
2º iteração: <p th:utext="" </p>.
3º iteração: <p th:utext="" </p>.
...
I was thinking that this happened because the object was only loading along with the page, but it does not seem to be the case, as it also displays in the first iteration of the function.
In the hope of solving this, I thought if I would have some way to point a direct id to the object, that way I could either directly display the function how much, at least, know if there is anything wrong with the content object.
So, my question: Is it possible to point an ID to object log
? Or, access the object through the form? Something like, for example, (formId).objet.content
? Or some other way ..?