How to display on a JSP page the attributes of an object that was passed in a list

2

I'm working on a Java Web project, using the Spring MVC framework.

I'm having trouble displaying information that comes from a list where analysts are registered.

The analyst name is displayed correctly, since name is a String attribute of an Analyzer class object. But when trying to display the CNPJ (String) of the Enterprise object (of the Company class), which in this case is an attribute of an Analyzer class object, the CNPJ number does not appear.

<c:forEach var="analista" items="${listAnalistas}" varStatus="status">  
    <a>Nome do analista: <c:out value="${analista.nome}" /> </a>
    <a>CNPJ da empresa: <c:out value="${analista.empresa.cnpj}" /></a>
</c:forEach>    

The list is populated in the Controller class:

  @RequestMapping(value = "/")
     public ModelAndView home() {
    List<Analista> listAnalistas = analistaDao.list();
    ModelAndView model = new ModelAndView("/home/home");
    model.addObject("listAnalistas", listAnalistas);

    return model;
}

Is there any way to display this information?

    
asked by anonymous 04.08.2015 / 19:49

2 answers

0

The problem has been solved by changing the Hibernate configuration file (hibernate.cfg.xml).

I had to add the following line:

<property name="enable_lazy_load_no_trans">true</property>
    
14.03.2016 / 20:27
2

Gabriel Polo , passes the class of your controller to forEach

<c:forEach var="analista" items="${"classe do seu model".listAnalistas}" varStatus="status">  
    <a>Nome do analista: <c:out value="${analista.nome}" /> </a>
    <a>CNPJ da empresa: <c:out value="${analista.empresa.cnpj}" /></a>
</c:forEach>
    
04.08.2015 / 20:59