Closed apps4u closed 8 years ago
This looks like you have some state in one of your beans (some PeopleService
or controller?) And you append the same data to this collection/cache, which is later passed to templating engine.
I was just testing templates so the controller method creates the array or people to pass to the view so that would run for each request.
@Controller
public class IndexController {
List<String> names = new ArrayList(Arrays.asList("jason", "peter", "monike", "eva"));
class Person {
public String firstName;
public String lastName;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}
List<Person> people = new ArrayList<Person>();
@RequestMapping(value = "/index", method = RequestMethod.GET)
public String index(Model model) {
Person p = new Person();
p.firstName = "jason";
p.lastName = "kristian";
Person p1 = new Person();
p1.firstName = "jhon";
p1.lastName = "other";
people.add(p);
people.add(p1);
model.addAttribute("people", people);
model.addAttribute("names", names);
return "index";
}
}
Sorry your Right I dont know how I missed it the List is declared out side of the request method and each run through I add to the list.
Im so sorry , I been looking at the same piece of code for that issue and I did not see it.
So please accept my apology.
It's fine, glad to be helpful as a debugger ;)
HI, Ive only just started using this package.
I'm using SpringBoot project and I created a test template which I'm passing a list of people Objects to the People Class has two properties firstName lastName now when I run the app the array of people a displayed on the page using the {{#each }} helper .
I've got 2 people objects so I get 3 row on the page when I reload the page I appends to the list the same 2 people again so each refresh is not reloading the page.
after reloading the page a few times this is what is displayed
HB
jason kristian
jhon other
jason kristian
jhon other
jason kristian
jhon other
jason kristian
jhon other
jason kristian
jhon other
jason kristian
jhon other