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

175
Visualizações
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 à 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