Ler atributo de um Action

0 respostas
U
Galera, tenho uma página JSP com o seguinte link:
<a href="../paciente/paciente!input.action">Pacientes</a> - Exames
a action de paciente está logo abaixo:
package action.paciente;

import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.persistencia.paciente.Paciente;
import com.persistencia.paciente.PacienteDAO;

public class PacienteAction extends ActionSupport {
    List<Paciente> lista;
    
	public List<Paciente> getLista() {
		return lista;
	}

	public void setLista(List<Paciente> lista) {
		this.lista = lista;
	}

	@Override
	public String execute() throws Exception {
		PacienteDAO dao = new PacienteDAO();
		lista = (List<Paciente>)dao.listAll(Paciente.class);		
		if (lista != null)
		{
			setLista(lista);
			return SUCCESS;
		}
		else
			return ERROR;		
	}
}
Agora minha JSP de exibição:
<%@taglib prefix="s" uri="/struts-tags"%>
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<%@page import="java.util.Iterator"%>
<%@page import="java.util.List"%>
<%@page import="com.persistencia.paciente.Paciente"%><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Pacientes</title>
</head>
<body>
<h1>Pacientes</h1>
<% List lista = (List)request.getAttribute("lista");
Iterator iterator = lista.iterator();
while (iterator.hasNext()){ 
   Paciente paciente = (Paciente)iterator.next();
%>
  <tr> 
    <td><%= paciente.getCodpac() %></td>
    <td><%= paciente.getNomeCompleto() %></td>
    <td><%= paciente.getPrtpac() %></td>
    <td><%= paciente.getSexpac() %></td>
  </tr>
<%}%>
</table>
</body>
</html>

O problema é que quando essa página de exibição é chamada ocorre o erro: Servlet.service() for servlet jsp threw exception.
Eu penso que prov. esse erro é por causa da atribuição do valor de 'lista', gostaria de saber se essa é a forma correta de acessar a variavel lista da Action.

Criado 6 de agosto de 2008
Respostas 0
Participantes 1