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

177
Visualizações
Thymeleaf inline javascript spring bean check for null with textual template modes

I can't wrap my head around the syntax of the Textual template modes feature of Thymeleaf. Im trying to access a bean (works fine) and call a getter from where i get an another object from. This object can be null and i need to check it before i access the string i need.

How can i do this in one line by using the [# th:if expressions from Thymeleaf?

<script th:inline="javascript">
        //This does not work (i have tried multiple things)
        var string = /*[# th:if="${@bean.getObject()}"][[${@bean.getObject().getString()}]][/]*/ null;
</script>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

There are a lot of ways to accomplish this, I would recommend the safe navigation operator for this:

<script th:inline="javascript">
  var string = /*[[${@bean.object?.string}]]*/ null;
</script>

You could also use a ternary expression:

<script th:inline="javascript">
  var string = /*[[${@bean.object != null ? @bean.object.string : null}]]*/ null;
</script>
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