Passando todos os arquivos, como o Marcelo sugeriu:
Bean - Grupos.Java:
package auge.bean;
import java.io.Serializable;
public class Grupos implements Serializable {
private Integer grupo;
private String descricao;
public Grupos() {
}
public Integer getGrupo() {
return this.grupo;
}
public String getDescricao() {
return this.descricao;
}
public void setGrupo(Integer grupo) {
this.grupo = grupo;
}
public void setDescricao(String descricao) {
this.descricao = descricao;
}
}
ListaGruposAction.java:
package auge.action;
import java.util.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.hibernate.HibernateException;
import auge.conexao.GruposService;
import auge.bean.Grupos;
import auge.form.ListaGruposForm;
public class ListaGruposAction extends Action {
public ActionForward execute (
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception {
List lista = GruposService.getInstance().getGruposList();
request.setAttribute("grupos", lista);
return mapping.findForward("ok");
}
}
Método getGruposList, na classe GruposService.java:
public List getGruposList() {
Session session = ConnectionFactory.getInstance().getSession();
try {
Query query =
session.createQuery(
"from auge.bean.Grupos gp order by gp.descricao");
return query.list();
} catch (HibernateException e) {
System.err.println("Hibernate Exception" + e.getMessage());
throw new RuntimeException(e);
} finally {
if (session != null) {
try {
session.close();
} catch (HibernateException e) {
System.err.println("Hibernate Exception" + e.getMessage());
throw new RuntimeException(e);
}
}
}
}
No struts-config.xml, tenho:
<form-beans>
<form-bean name="listaGruposForm" type="auge.form.ListaGruposForm"/>
</form-beans>
e também:
<action
path="/ListaGrupos"
type="auge.action.ListaGruposAction"
name="listaGruposForm" scope="request" validate="true"
input="/pages/grupos.jsp"
forward="/pages/gruposLista.jsp"/>
grupos.jsp:
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-layout.tld" prefix="layout" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Grupos</title>
<link rel="stylesheet" type="text/css" href="../config/estilos.css" />
<html:base/>
</head>
<body>
<span style="font-family:Sans-serif;">
<table width="100%" align="center">
<tr><td> Grupos </td></tr>
<tr bgcolor="#000000"> <td></td></tr>
</table>
<br>
<html:form action="/ListaGrupos" method="post" focus="descricao">
<table border="0" align="center">
<tr><td width="50%">Grupo: </td><td width="50%"><html:text property="descricao" /></td></tr>
<tr><td width="50%" align="center"><html:submit value="Buscar"/> </td><td width="50%" align="center"><html:reset value="Limpar"/></td></tr>
</table><br/>
</html:form>
<br>
<html:errors/>
</span>
</body>
</html>
Como podem perceber por esse arquivo, era pra escrever uma palavra e buscar o produto com nome parecido, mas nao implementei isso ainda (ou seja, nao espero que funcione desta forma, só o html está assim). Só o que devia fazer eh: ao escrever qq coisa no quadrinho e mandar buscar (assim ativando a action) ele trazer uma lista com todos, independente do nome.
gruposLista.jsp
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page import="auge.conexao.GruposService" %>
<%@ page import="java.util.*" %>
<html:html locale="true">
<head>
<title>Listagem de Grupos</title>
<html:base/>
</head>
<body bgcolor="white">
<html:errors/>
<%-- <%
List gruposList = GruposService.getInstance().getGruposList();
request.setAttribute("gruposLista", gruposList);
Iterator iterator = gruposList.iterator();
while (iterator.hasNext()) {
Object elem = iterator.next();
if (elem == null)
elem = "";
%>
<br> <%= elem %>
<%
}
%> --%>
<table border=1>
<tr>
<td>Grupo</td>
<td>Descrição</td>
</tr>
<logic:iterate id="element" name="grupos" scope="request" type="auge.bean.Grupos" >
<tr>
<td><bean:write name="element" property="grupo" /></td>
<td><bean:write name="element" property="descricao" /></td>
</tr>
</logic:iterate>
<%--
<c:forEach var="items" items="${grupos}">
<tr>
<td><c:out value="${items.grupo}" /></td>
<td><c:out value="${items.descricao}" /></td>
</tr>
</c:forEach>
--%>
</table>
<p>
<html:link action="/Grupos.do">Voltar</html:link>
</body>
</html:html>
Como podem ver nesse, tem mta coisa comentada hehehe… pq tentei de todos os jeitos, e de todos nada. O scriplet está comentado pra ver se funcionava com o action (jah q o scriplet tava saindo tudo em branco)… mas com a action e o logic-iterate tb nao dá certo, dá um erro dizendo “Cannot find bean grupos in scope request”…
Mas meu problema está bem antes disso, já que o hibernate estava retornando nulo no scriplet, onde ele devia retornar dados. Então coloco aqui também os arquivos do hibernate:
hibernate.cfg.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">org.firebirdsql.jdbc.FBDriver</property>
<property name="connection.url">jdbc:firebirdsql:127.0.0.1/3050:/E/BD/auge.gdb</property>
<property name="connection.username">sysdba</property>
<property name="connection.password">senha</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.FirebirdDialect</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">update</property>
<mapping resource="auge/bean/Grupos.hbm.xml"/>
</session-factory>
</hibernate-configuration>
log4j.properties: (este peguei aqui no GUJ mesmo, se não me engano foi até o Maurício q tinha passado pra outra pessoa)
log4j.rootLogger=DEBUG, dest1, dest2
log4j.appender.dest1=org.apache.log4j.ConsoleAppender
log4j.appender.dest1.layout=org.apache.log4j.PatternLayout
log4j.appender.dest1.layout.ConversionPattern=%d %-5p %-5c{3} %x -> %m%n
log4j.appender.dest2=org.apache.log4j.RollingFileAppender
log4j.appender.dest2.File=hibernate3.log
log4j.appender.dest2.layout=org.apache.log4j.PatternLayout
log4j.appender.dest2.layout.ConversionPattern=%-5c{2} %x -> %m%n
#log4j.appender.dest2.MaxFileSize=100KB
# Keep one backup file
#log4j.appender.dest2.MaxBackupIndex=3
#log4j.appender.dest2.layout=org.apache.log4j.PatternLayout
#log4j.appender.dest2.layout.ConversionPattern=%d [%t] %-5p %-5c{3}(%L) %x -> %m%n
Não tenho um arquivo hibernate.properties pq entendo que o hibernate.cfg.xml acaba com a necessidade dele… certo?
E por ultimo, Grupos.hbm.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="auge.bean.Grupos" table="GRUPOS" >
<id name="grupo" column="grupo" type="java.lang.Integer">
<generator class="assigned"/>
</id>
<property name="descricao" column="descricao" type="java.lang.String" />
</class>
</hibernate-mapping>
Bom, acho que é só isso que tenho de informação que seja relevante… e não é pouco hehehehe… continuo contando com a ajuda de vcs pra resolver. T+

