Skip to content

Instantly share code, notes, and snippets.

@samuelmale
Last active July 9, 2018 15:05
Show Gist options
  • Save samuelmale/add161d72519bdae57f91f8714fcc873 to your computer and use it in GitHub Desktop.
Save samuelmale/add161d72519bdae57f91f8714fcc873 to your computer and use it in GitHub Desktop.
public ModelAndView viewPersonDetailsById(PersonBean personbean,Model model) {
if (personbean.getCheckedIds()!= null) {
Integer [] ids = personbean.getCheckedIds();
List <PersonBean> people = new ArrayList<PersonBean>();
//Iterate over the ids and get matching 'Personels' required in next view
for (Integer id : ids) {
//Get the Person
person = userdao.getPersonDetailsById(id);
people.add(person);
}
//Now we shall interate over the people attribute from the jsp/gsp page
model.addAttribute("people", people);
return new ModelAndView("viewPersonDetailsById");
} else {
return new ModelAndView(" ");
}
}
public class PersonBean {
String name;
String age;
String status;
List<PersonBean> friends;
//Getters and Setters
}
<div id="list">
<!-- BTW, You wanna first check whether 'people' object exists in the page context -->
<c:forEach items="${people}" var="person">
<tr>
<td>${person.name}</td>
<td>${person.birthDate}</td>
<td>${person.status}</td>
<!-- Now interate over person friends -->
<td>
<ol>
<c:forEach items="${person.friends}" var="friend">
<li>${friend.name}<li>
</c:forEach>
</ol>
</td>
</tr>
</c:forEach>
</div>
@HerbertYiga
Copy link

<c:forEach items="${person.friends}" var="friend">

//some more explanation on the above code

@samuelmale
Copy link
Author

Its the same as a nested loop

@samuelmale
Copy link
Author

@samuelmale
Copy link
Author

@samuelmale
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment