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

173
Vistas
Access specific Set variables from Spring using Javascript

How do I access specific Set variables from Spring using Javascript?

My controller returns a data set containing the following information from multiple classes

Person
    String firstName;
    String lastName;
    int age;

Address
    String country;
    String city;

Which is passed to the html as model.addAttribute("personSet", form);

When it gets passed to the html, the data becomes like so:

Set1
 (from Person Class)
 firstName = John
 lastName = Doe
 age = 20
 
 (from Address Class)
 country = Japan
 city = Tokyo
 
Set 2
 (from Person Class)
 firstName = Mary
 lastName = Smith
 age = 30
 
 (from Address Class)
 country = Korea
 city = Seoul

What I'm trying to do with javascript is that I want to get the specific variable data so I can perform an if condition for every item in the set. For example: For every person in personSet, if country = Japan, print firstName + lastName.

To solve this I created the following code

Please note I removed some variable declarations and this is an in-line js code snippet containing the following code:

<script th:inline="javascript"> and /*<![CDATA[*/

    function printPeopleFromJapan() {
    //get the data of the whole set
    personSetJS = /*[[${personSet.Person}]]*/'default';
    
    //loop through all persons in the set
    for (person of personSet) {
        country = /*[[${personSet.country}]]*/'default';
            
        //if country is equal to Japan, get the person full name
        if (country == "Japan") {
            personFirstName = /*[[${personSet.firstName}]]*/'default';
            personLastName = /*[[${personSet.lastName}]]*/'default';
            console.log(personFirstName + personLastName);
        }
    }
}

But my program doesn't run and I'm getting errors and a blank page.

Caused by: org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "personSet.Person" 

Please help.

about 4 years ago · Juan Pablo Isaza
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