Question

I'm new in spring mvc and jstl, and i want to display a set of objects in my jsp page, that are my two classes :

Class Phase{
 private Set<Tache> taches;
}

Class Tache{
 private String name;
} 

Class Controller{
 @RequestMapping(value="/pages/index")
public  String pageProject(Model model){
    model.addAttribute("phaseList", phaseService.getAllPhases());
 return "/pages/createProject";
}

Class PhaseDAO{
 @Override
public List<Phase> getAllPhases() {
    Session session =  HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();
    return session.createQuery("from Phase").list();
}
}
Class PhaseService{
@Transactional
public List<Phase> getAllPhases() {
    // TODO Auto-generated method stub
    return phaseDao.getAllPhases();
}
}

And in my JSP :

j:forEach items="phaseList" var="phase" <br>
    ${phase.taches} <br>
/j:forEach

So i want to display in a jsp page Taches per Phase.

Please help me !

Était-ce utile?

La solution

You have a list of Phases. Each phase has a list of Taches. Simple logic would suggest you need two loops:

<c:forEach var="phase" items="${phaseList}">
    <c:forEach var="tache" items="${phase.taches}">
        <tr>
            <td>${tache.name}</td>
        </tr> 
    </c:forEach>
</c:forEach>

Autres conseils

Here is example getting list of objects in jsp and dispaly

<c:forEach var="object" items="${phaseList}">

                            <tr>
                            <td> <c:out value="${status.attribute}"/></td>
                        </tr> 
                        </c:forEach>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top