Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

443
Visualizações
How can I call javascript function in thymeleaf th:if?

I want to call javascript function in 'th:if'. This is my code.

<li th:each="dto, stat : ${list}" th:if="${stat.count>10}">
   <span th:if="'javascript:isNew('+${dto.regDts}+');'">blah blah</span>
</li>

...

<script th:inline="javascript">
 function isNew(date) {
     if (...) {
        return true;
     }
     return false;
 }
</script>

but it doesn't call isNew().

so when I wrote like this...

 <span th:if="isNew(${dto.regDts});">blah blah</span>

i got an error.

how can I call javascript function in "th:if"?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Thymeleaf generates HTML in the server and passes that to the browser. At that point, Thymeleaf is no longer "active". JavaScript runs in the browser using the HTML that Thymeleaf has generated. So it is impossible to do what you want like this.

The easiest solution is to add an extra method or property on the Java object that is used. Suppose you add an isNew() method on your dto, then you can do:

<li th:each="dto, stat : ${list}" th:if="${stat.count>10}">
   <span th:if="${dto.new}">blah blah</span>
</li>
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda