[STRUTS] Problema ao listar

2 respostas
K

Estou com um problema aqui no listar, pq ele direciona para a página certa mas não exibe nenhuma lista. Está com stacktrace de 'javax.servlet.jsp.JspException: Cannot create iterator for this collection'

vou colar os códigos aki.

meu struts-config.xml
<!-- Item -->

        <action path="/item" type="br.com.ufrj.action.itemHomeAction" name="optionBean" input="/admin_itemHome.jsp" scope="request" validate="false">
            <forward name="inserir" path="/admin_itemInserir.jsp" />
            <forward name="listar" path="/admin_itemLista.jsp" />
            <forward name="voltar" path="/admin_index.jsp" />
        </action>

        <action path="/updateItem" type="br.com.ufrj.action.UpdateActionItem"
            name="BeanItem" input="/admin_itemInserir.jsp" scope="request" validate="true">
            <forward name="successo" path="/admin_index.jsp" />
            <forward name="voltar" path="/admin_index.jsp" />
        </action>

         <action path="/listaItem" type="br.com.ufrj.action.listActionItem"
            name="BeanItem" input="/admin_itemLista.jsp" scope="request" validate="true" >
            <forward name="voltar" path="/admin_index.jsp" />
        </action>

        <!--Item -->
meu jsp
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>


<html>
    <head>
        <title>Gerenciamento de Hotel</title>
    </head>

    <body>
        <h1>Gerenciamento de Itens</h1>
        <h1>Gerenciamento de Itens</h1>
        <h1>Gerenciamento de Itens</h1>
        <html:form action="listaItem.do">
            <div id="container">
                <br>
                <logic:iterate id="lista" name="BeanItem">
                    aaaa<bean:write name="BeanItem" property="nome"/>
                </logic:iterate>
            </div>
       
    </html:form>
         </body>
</html>
meu action
package br.com.ufrj.action;

import br.com.ufrj.item.*;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.*;

public class listActionItem extends Action {

    public ActionForward perform(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response) throws Exception {
        HttpSession session = request.getSession();
        ActionMessages messages = new ActionMessages();
        ActionErrors erros = new ActionErrors();

        DAOItem dao = new DAOItem();
        ArrayList<BeanItem> list = new ArrayList<BeanItem>();

        list = dao.selectAllItems();

        request.setAttribute("lista",list);

        return mapping.findForward("ok");

    }
}
minha DAO de acesso ao banco
public ArrayList<BeanItem> selectAllItems() throws Exception {

        try {
            String query = "SELECT * " + "FROM item " + "ORDER BY id ";

            xConn = new XConnection();
            xConn.rs = xConn.seleciona(query);

            ArrayList<BeanItem> lItem = new ArrayList<BeanItem>();

            while (xConn.rs.next()) {
                BeanItem item = new BeanItem();
                item.setId(Integer.parseInt(xConn.rs.getString(1)));
                item.setNome(xConn.rs.getString(2));
                item.setDescricao(xConn.rs.getString(3));
                item.setValor(Float.parseFloat(xConn.rs.getString(5)));
                lItem.add(item);
            }

            xConn.fechaConexao();

            return lItem;

        } catch (SQLException e) {
            System.out.println("erro selectAllItens: " + e.toString());
            xConn.fechaConexao();
            return null;
        } catch (Exception e) {
            System.out.println("erro select All  Itens: " + e.toString());
            xConn.fechaConexao();
            return null;
        }

    }

Desculpe por tantos códigos , mas é mais facil identificar assim.

Obrigado galera.

2 Respostas

wbdsjunior

você inverteu o nome da lista com a “variável” que ela cria na tag logic:iterate.

troque

&lt;logic:iterate id="lista" name="BeanItem"&gt;

por

&lt;logic:iterate id="BeanItem" name="lista"&gt;
K

agora o stacktrace mudou

Cannot find bean: “lista” in any scope

pode ser pq eu n tenho um get e set dessa lista?

e se preciso gerar…eu vou substituir no meu struts-config meu “BeanItem” por ‘BeanLista’ ?

Criado 8 de dezembro de 2010
Ultima resposta 8 de dez. de 2010
Respostas 2
Participantes 2