Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

170
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!