rdmardegam:
Amigo neste link tem um exemplo de como utilizar coleção para renderizar as informações no seu relatorio:
[url]http://webcache.googleusercontent.com/search?q=cache:2esiHMNv7JoJ:www.furutani.com.br/site/MostrarArtigo.action%3Fcodigo%3D10+exemplo+ireport+com+JRBeanCollectionDataSource&cd=1&hl=pt-BR&ct=clnk&gl=br[/url]
Abraço.
Cara, dei uma olhada no método lá do exemplo que vc me passou, e nada...
Estou começando a achar que está tendo algum problema com o facesServlet ou com o facelets.
Olha como está meu xhtml que me retorna a lista com os orgaosgestores:
<f:view>
<body>
<h:form id="nomeLabel">
<rich:dataTable value="#{orgaogestorHandler.orgaosGestoresByNome}" var="f" rendered="#{not empty orgaogestorHandler.orgaosGestoresByNome}" rows="5" id="orgaosGestoresByNome">
<h:column>
<f:facet name="header">
<h:outputText value="Código"/>
</f:facet>
<h:outputText value="#{f.cod_orgaogestor}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Nome"/>
</f:facet>
<h:outputText value="#{f.nome}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Relatório"/>
</f:facet>
<center>
<h:commandButton value="PDF" id="pdf" actionListener="#{orgaogestorHandler.imprimirRelatorio}"/>
</center>
</h:column>
<f:facet name="footer">
<rich:datascroller/>
</f:facet>
</rich:dataTable>
</h:form>
</body>
</f:view>
meu método no bean está assim:
private String getDiretorioReal(String diretorio) {
HttpSession session = (HttpSession) FacesContext.getCurrentInstance()
.getExternalContext().getSession(false);
System.out.println("getDireitorioReal");
return session.getServletContext().getRealPath(diretorio);
}
private String getContextPath() {
HttpSession session = (HttpSession) FacesContext.getCurrentInstance()
.getExternalContext().getSession(false);
System.out.println("getContextPath");
return session.getServletContext().getContextPath();
}
private void preenchePdf(JasperPrint print) throws JRException {
// Pego o caminho completo do PDF desde a raiz
saida = getDiretorioReal("/pdf/relatorio.pdf");
// Exporto para PDF
JasperExportManager.exportReportToPdfFile(print, saida);
saida = getContextPath() + "/pdf/relatorio.pdf";
}
public void imprimirRelatorio() {
saida = null;
System.out.println("metodo de impressao");
String jasper = getDiretorioReal("/jasper/orgaogestor.jasper");
Connection conexao = null;
try {
// Abro a conex�o com o banco que ser� passada para o JasperReports
conexao = new Conexao().getConexao();
JRResultSetDataSource jrds = new JRResultSetDataSource(
getResultSet(conexao));
// Mando o jasper gerar o relat�rio
JasperPrint print = JasperFillManager
.fillReport(jasper, null, jrds);
// Gero o PDF
preenchePdf(print);
System.out.println("pdf gerado");
} catch (Exception e) {
e.printStackTrace();
System.out.println("erro: " + e);
} finally {
try {
// // Sempre mando fechar a conex�o, mesmo que tenha dado erro
if (conexao != null)
conexao.close();
} catch (Exception e) {
}
}
}
private ResultSet getResultSet(Connection conexao) throws SQLException,
ClassNotFoundException {
Statement stmt = conexao.createStatement();
ResultSet rs = stmt
.executeQuery("SELECT internet.tipo AS internet_tipo, "
+ "nivelgestao.tipo AS gestao_tipo, *, FROM orgaogestor, municipiosrr, nivelgestao, estados, internet");
return rs;
}
meu web.xml está assim (de repente, pode ser algum problema nele...):
<?xml version="1.0"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm </welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX </param-name>
<param-value>.xhtml </param-value>
</context-param>
<context-param>
<param-name>facelets.DEVELOPMENT </param-name>
<param-value>true </param-value>
</context-param>
<context-param>
<param-name>com.sun.faces.validateXml </param-name>
<param-value>false </param-value>
</context-param>
<context-param>
<param-name>com.sun.faces.verifyObjects </param-name>
<param-value>true </param-value>
</context-param>
<!-- Configura onde salvar o estado dos componentes. O padrao é server -->
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
<!-- Configura o filtro obrigatorio do Ajax4Jsf -->
<filter>
<display-name>Ajax4jsf Filter</display-name>
<filter-name>ajax4jsf</filter-name>
<filter-class>org.ajax4jsf.Filter</filter-class>
</filter>
<filter-mapping>
<filter-name>ajax4jsf</filter-name>
<servlet-name>Faces Servlet</servlet-name>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
<filter>
<filter-name>HibernateSessionFilter</filter-name>
<filter-class>br.gov.rr.setrabes.util.HibernateSessionFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>HibernateSessionFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Configura a servlet do JSF. -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
<!-- SERVLET PARA IREPORTS
<servlet>
<servlet-name>ServletCategoria</servlet-name>
<servlet-class>br.gov.rr.setrabes.ireports.ServletCategoria</servlet-class>
</servlet>
<servlet>
<servlet-name>VisualizaRelatorio</servlet-name>
<servlet-class>br.gov.rr.setrabes.ireports.VisualizaRelatorio</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ServletCategoria</servlet-name>
<url-pattern>/ServletCategoria</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>VisualizaRelatorio</servlet-name>
<url-pattern>/VisualizaRelatorio</url-pattern>
</servlet-mapping> -->
<context-param>
<param-name>facelets.SKIP_COMMENTS</param-name>
<param-value>true</param-value>
</context-param>
<!-- Ativando o Skin -->
<context-param>
<param-name>org.richfaces.CONTROL_SKINNING</param-name>
<param-value>enable</param-value>
</context-param>
<!-- Define a skin do richfaces. Ha varias opcoes -->
<context-param>
<param-name>org.richfaces.SKIN</param-name>
<!--<param-value>.xhtml</param-value> -->
<!--<param-value>DEFAULT</param-value>-->
<!--<param-value>plain</param-value>-->
<!--<param-value>emeraldTown</param-value>-->
<param-value>blueSky</param-value>
<!-- <param-value>wine</param-value>-->
<!-- <param-value>japanCherry</param-value>-->
<!--<param-value>ruby</param-value>-->
<!--<param-value>classic</param-value>-->
<!-- <param-value>deepMarine</param-value>-->
</context-param>
<context-param>
<param-name>org.ajax4jsf.SKIN</param-name>
<param-value>blueSky</param-value>
</context-param>
<!-- Definindo e mapeando os filtros do RichFaces -->
<filter>
<display-name>RichFaces Filter</display-name>
<filter-name>richfaces</filter-name>
<filter-class>org.ajax4jsf.Filter</filter-class>
</filter>
<filter-mapping>
<filter-name>richfaces</filter-name>
<servlet-name>Faces Servlet</servlet-name>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
<!-- Fim da configuracao do RIchFaces -->
<!-- Definindo e mapeando os filtros do RichFaces -->
<context-param>
<param-name>org.ajax4jsf.VIEW_HANDLERS</param-name>
<param-value>com.sun.facelets.FaceletViewHandler</param-value>
</context-param>
<context-param>
<param-name>facelets.REFRESH_PERIOD</param-name>
<param-value>1</param-value>
</context-param>
<context-param>
<param-name>facelets.RECREATE_VALUE_EXPRESSION_ON_BUILD_BEFORE_RESTORE</param-name>
<param-value>false</param-value>
</context-param>
</web-app>
Eae, o que vc acha??
Vlw