Last active
July 9, 2018 15:05
-
-
Save samuelmale/add161d72519bdae57f91f8714fcc873 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(" "); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PersonBean { | |
String name; | |
String age; | |
String status; | |
List<PersonBean> friends; | |
//Getters and Setters | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
Its the same as a nested loop
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
<c:forEach items="${person.friends}" var="friend">
//some more explanation on the above code