Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

174
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda