<c:forEach não le lista de dados

2 respostas
fsalex

Pessoal,

Estou com um grande problema aqui…estou usando Jboss 4.0 com struts e na pagina uso jstl, o proble é o seguinte:
Todas as tags jstl abrem e funciona normalsó o <c:forEach que esta com um problema quando tento ler uma List, olhem como esta:

Action:
.
.
.
testeDTO = testeService.find(form.getNome());

pRequest.setAttribute(“lista”, testeDTO);

return pMapping.findForward(FORWARD);

Form:

private String nome;

public String getNome() {

return nome;

}
public void setNome(String nome) {

this.nome = nome;

}

JSP que não funciona:

<c:forEach items="${testeDTO}" var=“lista”>

<c:out value="${lista.nome}"></c:out>

</c:forEach>

O erro que gera:
type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Exception in JSP: /WEB-INF/jsp/index.jsp:20

17: 	<bean:message key=“label.nome”/>: <html:text property=“nome”/><html:submit value=“Enviar”></html:submit>

18: 	


19: 	

20: 	<c:forEach items="${lista}" var=“lista”>

21: 	<c:out value="${lista.nome}"></c:out>

22: 	</c:forEach>

23:

JSP que funciona:

<c:forEach begin=“1” end=“10”>
a
</c:forEach>

Se alguem souber fico grato…

Abraços…

2 Respostas

fabiozoroastro

Olá, você está usando o c:forEach em um atributo que não existe na request.

pRequest.setAttribute("lista", testeDTO);  // Atributo na request: lista
<c:forEach items="${testeDTO}" var="lista">  // testeDTO não existe na request.

Substitua o c:forEach por:

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

Ps.: Veja como utilizar BBCode para fazer seus posts aqui no fórum.

fsalex

Olá…

Eu alterei e ainda contiua dando o mesmo erro:

pRequest.setAttribute("lista", testeDTO);  // Atributo na request: lista 
  
&lt;c:forEach items="${lista}" var="lista"&gt;  // lista agora existe na request.  
&lt;c:out value="${lista.nome}"&gt;&lt;/c:out&gt;
&lt;/c:forEach &gt;

o erro ainda continua o mesmo:

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Exception in JSP: /WEB-INF/jsp/index.jsp:20

17: <bean:message key=“label.nome”/>: <html:text property=“nome”/><html:submit value=“Enviar”></html:submit>

18: 


19:

20: <c:forEach items="${lista}" var=“lista”>

21: <c:out value="${lista.nome}"></c:out>

22: </c:forEach>

23:

Vlw pela ajuda

Criado 21 de julho de 2009
Ultima resposta 21 de jul. de 2009
Respostas 2
Participantes 2