Problema ao chamar relatorio do iReport dento de aplicação JSF

1 resposta
M

Pessoal,

Estou tentando chamar um relatório feito no iReport através do seguinte método

...
public boolean chamarRelatorio() {
		String caminhoRelJasper = "/br/ufpb/nti/diploma/ireport/jrxml/report1.jrxml";
		
		InputStream relJasper = getClass().getResourceAsStream(caminhoRelJasper);
		
		Map parametros = new HashMap();
		parametros.put("situacao", 1);
		
		GerarPDFCompilando gera = new GerarPDFCompilando();
		try{
			gera.geraPDFaqui(relJasper, parametros);
			return true;
		}
		catch(Exception e){
			return false;
		}
	}
...

Abaixo, segue o código da classe GerarPDFCompilando com o metodo geraPDFaqui

public class GerarPDFCompilando{
     
    public GerarPDFCompilando() {
        
    }
    
    public void geraPDFaqui(InputStream relJasper, Map parametros) throws IOException, ClassNotFoundException, SQLException {
            FacesContext facesContext = FacesContext.getCurrentInstance();
            HttpServletRequest request = (HttpServletRequest) facesContext.getExternalContext().getRequest();
            HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();
   
           Connection con = ConexaoDB.getInstance();
          
            JasperPrint impressao = null;

		try {
                    JasperReport jasper = JasperCompileManager.compileReport(relJasper);
			//Conversão do Formato Jasper para PDF. Aqui irá gerar o Arquivo para o usuário.
			impressao = JasperFillManager.fillReport(jasper, parametros, con);
                        byte[] bytes = JasperExportManager.exportReportToPdf(impressao);
                        response.setHeader("Content-Disposition", "attachment; filename=PRPG.pdf"); 
                        response.setContentType("application/pdf");
                        response.setContentLength(bytes.length);
                        ServletOutputStream ouputStream = response.getOutputStream();
                        ouputStream.write(bytes, 0, bytes.length);
                        ouputStream.flush();
                        ouputStream.close();      

		} catch (JRException e) {
			System.out.println(e.getMessage());
		}
    }
}

E abaixo a chamada do método na página

...
<div>
<h:commandButton action="#{consultaDiplomaBean.chamarRelatorio}" value="Gerar Relatorio" rendered="true" style="margin-left:300px; margin-top:10px"/>
</div>
...

Ao usar o debug do Eclipse, percebi que está sendo atribuída uma referência NULL ao objeto relJasper no início do método chamarRelatorio

...
InputStream relJasper = getClass().getResourceAsStream(caminhoRelJasper);
...

Alguém poderia me ajudar a descobrir o motivo pelo qual está ocorrendo esta referência NULL ?
Agradece,

Max Carvalho

1 Resposta

juniorsatanas
package br.empresateste.testerelatorio.bean;



import java.sql.Connection;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

import java.util.ArrayList;

import java.util.HashMap;

import java.util.Map;



import javax.faces.context.FacesContext;

import javax.servlet.http.HttpSession;



import net.sf.jasperreports.engine.JRException;

import net.sf.jasperreports.engine.JRResultSetDataSource;

import net.sf.jasperreports.engine.JasperExportManager;

import net.sf.jasperreports.engine.JasperFillManager;

import net.sf.jasperreports.engine.JasperPrint;

import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;

import br.empresateste.testerelatorio.conexao.Conexao;

import br.empresateste.testerelatorio.dao.AlunoDao;

import br.empresateste.testerelatorio.model.Aluno;



public class RelatorioBean {



	private String saida;

	

	public String geraRelatorioPassandoConexao() {

		saida = null;

		String jasper = getDiretorioReal("/jasper/professores_por_aluno.jasper");

		Connection conexao = null;



		try {

			

			conexao = new Conexao().getConexao();

			

			JasperPrint print = JasperFillManager.fillReport(jasper, null, conexao);

			

			preenchePdf(print);

		} catch (Exception e) {

			e.printStackTrace();

		} finally {

			try {

				if (conexao != null)

					conexao.close();

			} catch (SQLException e) {

				

			}

		}

		

		return "exibeRelatorio";

	}

	

	public String geraRelatorioPassandoResultSet() {

		saida = null;

		String jasper = getDiretorioReal("/jasper/professores_por_aluno.jasper");

		Connection conexao = null;



		try {

			

			conexao = new Conexao().getConexao();

			

			JRResultSetDataSource jrsds = new JRResultSetDataSource(getResultSet(conexao));

			

			JasperPrint print = JasperFillManager.fillReport(jasper, null, jrsds);

			

			preenchePdf(print);

		} catch (Exception e) {

			e.printStackTrace();

		} finally {

			try {

				

				if (conexao != null)

					conexao.close();

			} catch (SQLException e) {

				

			}

		}

		

		return "exibeRelatorio";

	}



	

	public String geraRelatorioPassandoListaDeObjetos() {

		saida = null;

		String jasper = getDiretorioReal("/jasper/professores_por_aluno_com_lista.jasper");

		Connection conexao = null;

		

		try {

			

			conexao = new Conexao().getConexao();

			

			Map&lt;String, Object&gt; map = new HashMap&lt;String, Object&gt;();

		

			map.put("REPORT_CONNECTION", conexao);

			

			map.put("SUBREPORT_DIR", getDiretorioReal("/jasper/") + "/");

			ArrayList&lt;Aluno&gt; alunos = getListaAlunos(conexao);



			JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(alunos);

		

			JasperPrint print = JasperFillManager.fillReport(jasper, map, ds);

			

			preenchePdf(print);

		} catch (Exception e) {

			e.printStackTrace();

		}

		

		return "exibeRelatorio";

	}

	



	private ResultSet getResultSet(Connection conexao) throws SQLException, ClassNotFoundException {

		Statement stmt = conexao.createStatement();

				

		ResultSet rs = stmt.executeQuery("SELECT aluno.nome AS aluno_nome, " +

				"aluno.matricula AS aluno_matricula, professor.nome AS professor_nome, " +

				"aluno.id_aluno AS aluno_id_aluno FROM aluno aluno " +

				"INNER JOIN professores_alunos professores_alunos ON aluno.id_aluno = professores_alunos.id_aluno " +

				"INNER JOIN `professor` professor ON professores_alunos.id_professor = professor.id_professor");

		

		return rs;

	}

	

	private ArrayList&lt;Aluno&gt; getListaAlunos(Connection conexao) throws SQLException {

		return (ArrayList&lt;Aluno&gt;) new AlunoDao().loadAll(conexao);

	}

	

	private void preenchePdf(JasperPrint print) throws JRException {

		

		saida = getDiretorioReal("/pdf/relatorio.pdf");

		

		JasperExportManager.exportReportToPdfFile(print, saida);

		

		saida = getContextPath() + "/pdf/relatorio.pdf";

	}

	

	private String getDiretorioReal(String diretorio) {

		HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);

		return session.getServletContext().getRealPath(diretorio);

	}

	

	private String getContextPath() {

		HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);

		return session.getServletContext().getContextPath();

	}

	

	public String getSaida() {

		return saida;

	}



	public void setSaida(String saida) {

		this.saida = saida;

	}

	

}
package br.empresateste.testerelatorio.conexao;



import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.SQLException;



public class Conexao {

	private Connection conexao;



	public Conexao() throws ClassNotFoundException, SQLException {

		criaConexao();

	}



	public void criaConexao() throws ClassNotFoundException, SQLException {

		String endereco = "localhost";

		String porta = "3306";

		String banco = "academico";

		String usuario = "root";

		String senha = "debian23";



		try {

			Class.forName("com.mysql.jdbc.Driver");

			conexao = DriverManager.getConnection("jdbc:mysql://" + endereco

					+ ":" + porta + "/" + banco + "?user=" + usuario

					+ "&password=" + senha);



		} catch (ClassNotFoundException ex) {

			throw ex;

		} catch (SQLException ex) {

			throw ex;

		}



	}



	public void fechaConexao() throws SQLException {

		conexao.close();

		conexao = null;

	}



	public boolean isFechada() {

		try {

			return conexao.isClosed();

		} catch (SQLException ex) {

			return false;

		}

	}



	public Connection getConexao() {

		return conexao;

	}



}
package br.empresateste.testerelatorio.dao;



import java.sql.Connection;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.util.ArrayList;

import java.util.List;



import br.empresateste.testerelatorio.exception.NotFoundException;

import br.empresateste.testerelatorio.model.Aluno;



public class AlunoDao {





    public Aluno createValueObject() {

          return new Aluno();

    }



    public Aluno getObject(Connection conn, int idAluno) throws NotFoundException, SQLException {



          Aluno valueObject = createValueObject();

          valueObject.setIdAluno(idAluno);

          load(conn, valueObject);

          return valueObject;

    }



    public void load(Connection conn, Aluno valueObject) throws NotFoundException, SQLException {



          String sql = "SELECT * FROM aluno WHERE (id_aluno = ? ) "; 

          PreparedStatement stmt = null;



          try {

               stmt = conn.prepareStatement(sql);

               stmt.setInt(1, valueObject.getIdAluno()); 



               singleQuery(conn, stmt, valueObject);



          } finally {

              if (stmt != null)

                  stmt.close();

          }

    }



    public List&lt;Aluno&gt; loadAll(Connection conn) throws SQLException {



          String sql = "SELECT * FROM aluno ORDER BY id_aluno ASC ";

          List&lt;Aluno&gt; searchResults = listQuery(conn, conn.prepareStatement(sql));



          return searchResults;

    }



    public synchronized void create(Connection conn, Aluno valueObject) throws SQLException {



          String sql = &quot;&quot;;

          PreparedStatement stmt = null;

          ResultSet result = null;



          try {

               sql = &quot;INSERT INTO aluno ( nome, matricula, situacao_frequencia, &quot;

               + &quot;situacao_pagamento) VALUES (?, ?, ?, ?) &quot;;

               stmt = conn.prepareStatement(sql);



               stmt.setString(1, valueObject.getNome()); 

               stmt.setString(2, valueObject.getMatricula()); 

               stmt.setString(3, valueObject.getSituacaoFrequencia()); 

               stmt.setString(4, valueObject.getSituacaoPagamento()); 



               int rowcount = databaseUpdate(conn, stmt);

               if (rowcount != 1) {

                    //System.out.println(&quot;PrimaryKey Error when updating DB!&quot;);

                    throw new SQLException(&quot;PrimaryKey Error when updating DB!&quot;);

               }



          } finally {

              if (stmt != null)

                  stmt.close();

          }



          sql = &quot;SELECT last_insert_id()&quot;;



          try {

              stmt = conn.prepareStatement(sql);

              result = stmt.executeQuery();



              if (result.next()) {



                   valueObject.setIdAluno((int)result.getLong(1));



              } else {

                   //System.out.println(&quot;Unable to find primary-key for created object!&quot;);

                   throw new SQLException(&quot;Unable to find primary-key for created object!&quot;);

              }

          } finally {

              if (result != null)

                  result.close();

              if (stmt != null)

                  stmt.close();

          }



    }



    public void save(Connection conn, Aluno valueObject) 

          throws NotFoundException, SQLException {



          String sql = &quot;UPDATE aluno SET nome = ?, matricula = ?, situacao_frequencia = ?, &quot;

               + &quot;situacao_pagamento = ? WHERE (id_aluno = ? ) &quot;;

          PreparedStatement stmt = null;



          try {

              stmt = conn.prepareStatement(sql);

              stmt.setString(1, valueObject.getNome()); 

              stmt.setString(2, valueObject.getMatricula()); 

              stmt.setString(3, valueObject.getSituacaoFrequencia()); 

              stmt.setString(4, valueObject.getSituacaoPagamento()); 



              stmt.setInt(5, valueObject.getIdAluno()); 



              int rowcount = databaseUpdate(conn, stmt);

              if (rowcount == 0) {

                   //System.out.println(&quot;Object could not be saved! (PrimaryKey not found)&quot;);

                   throw new NotFoundException(&quot;Object could not be saved! (PrimaryKey not found)&quot;);

              }

              if (rowcount &gt; 1) {

                   //System.out.println(&quot;PrimaryKey Error when updating DB! (Many objects were affected!)&quot;);

                   throw new SQLException(&quot;PrimaryKey Error when updating DB! (Many objects were affected!)&quot;);

              }

          } finally {

              if (stmt != null)

                  stmt.close();

          }

    }



    public void delete(Connection conn, Aluno valueObject) 

          throws NotFoundException, SQLException {



          String sql = &quot;DELETE FROM aluno WHERE (id_aluno = ? ) &quot;;

          PreparedStatement stmt = null;



          try {

              stmt = conn.prepareStatement(sql);

              stmt.setInt(1, valueObject.getIdAluno()); 



              int rowcount = databaseUpdate(conn, stmt);

              if (rowcount == 0) {

                   //System.out.println(&quot;Object could not be deleted (PrimaryKey not found)&quot;);

                   throw new NotFoundException(&quot;Object could not be deleted! (PrimaryKey not found)&quot;);

              }

              if (rowcount &gt; 1) {

                   //System.out.println(&quot;PrimaryKey Error when updating DB! (Many objects were deleted!)&quot;);

                   throw new SQLException(&quot;PrimaryKey Error when updating DB! (Many objects were deleted!)&quot;);

              }

          } finally {

              if (stmt != null)

                  stmt.close();

          }

    }





    public void deleteAll(Connection conn) throws SQLException {



          String sql = &quot;DELETE FROM aluno&quot;;

          PreparedStatement stmt = null;



          try {

              stmt = conn.prepareStatement(sql);

              databaseUpdate(conn, stmt);

          } finally {

              if (stmt != null)

                  stmt.close();

          }

    }



    public int countAll(Connection conn) throws SQLException {



          String sql = &quot;SELECT count(*) FROM aluno&quot;;

          PreparedStatement stmt = null;

          ResultSet result = null;

          int allRows = 0;



          try {

              stmt = conn.prepareStatement(sql);

              result = stmt.executeQuery();



              if (result.next())

                  allRows = result.getInt(1);

          } finally {

              if (result != null)

                  result.close();

              if (stmt != null)

                  stmt.close();

          }

          return allRows;

    }



    public List&lt;Aluno&gt; searchMatching(Connection conn, Aluno valueObject) throws SQLException {



          List&lt;Aluno&gt; searchResults;



          boolean first = true;

          StringBuffer sql = new StringBuffer("SELECT * FROM aluno WHERE 1=1 ");



          if (valueObject.getIdAluno() != 0) {

              if (first) { first = false; }

              sql.append("AND id_aluno = ").append(valueObject.getIdAluno()).append(" ");

          }



          if (valueObject.getNome() != null) {

              if (first) { first = false; }

              sql.append("AND nome LIKE '").append(valueObject.getNome()).append("%' ");

          }



          if (valueObject.getMatricula() != null) {

              if (first) { first = false; }

              sql.append("AND matricula LIKE '").append(valueObject.getMatricula()).append("%' ");

          }



          if (valueObject.getSituacaoFrequencia() != null) {

              if (first) { first = false; }

              sql.append("AND situacao_frequencia LIKE '").append(valueObject.getSituacaoFrequencia()).append("%' ");

          }



          if (valueObject.getSituacaoPagamento() != null) {

              if (first) { first = false; }

              sql.append("AND situacao_pagamento LIKE '").append(valueObject.getSituacaoPagamento()).append("%' ");

          }





          sql.append("ORDER BY id_aluno ASC ");



          // Prevent accidential full table results.

          // Use loadAll if all rows must be returned.

          if (first)

               searchResults = new ArrayList&lt;Aluno&gt;();

          else

               searchResults = listQuery(conn, conn.prepareStatement(sql.toString()));



          return searchResults;

    }





    public String getDaogenVersion() {

        return "DaoGen version 2.4.1";

    }



    protected int databaseUpdate(Connection conn, PreparedStatement stmt) throws SQLException {



          int result = stmt.executeUpdate();



          return result;

    }



    protected void singleQuery(Connection conn, PreparedStatement stmt, Aluno valueObject) 

          throws NotFoundException, SQLException {



          ResultSet result = null;



          try {

              result = stmt.executeQuery();



              if (result.next()) {



                   valueObject.setIdAluno(result.getInt("id_aluno")); 

                   valueObject.setNome(result.getString("nome")); 

                   valueObject.setMatricula(result.getString("matricula")); 

                   valueObject.setSituacaoFrequencia(result.getString("situacao_frequencia")); 

                   valueObject.setSituacaoPagamento(result.getString("situacao_pagamento")); 



              } else {

                    //System.out.println("Aluno Object Not Found!");

                    throw new NotFoundException("Aluno Object Not Found!");

              }

          } finally {

              if (result != null)

                  result.close();

              if (stmt != null)

                  stmt.close();

          }

    }





    protected List&lt;Aluno&gt; listQuery(Connection conn, PreparedStatement stmt) throws SQLException {



          ArrayList&lt;Aluno&gt; searchResults = new ArrayList&lt;Aluno&gt;();

          ResultSet result = null;



          try {

              result = stmt.executeQuery();



              while (result.next()) {

                   Aluno temp = createValueObject();



                   temp.setIdAluno(result.getInt("id_aluno")); 

                   temp.setNome(result.getString("nome")); 

                   temp.setMatricula(result.getString("matricula")); 

                   temp.setSituacaoFrequencia(result.getString("situacao_frequencia")); 

                   temp.setSituacaoPagamento(result.getString("situacao_pagamento")); 



                   searchResults.add(temp);

              }



          } finally {

              if (result != null)

                  result.close();

              if (stmt != null)

                  stmt.close();

          }



          return (List&lt;Aluno&gt;)searchResults;

    }





}
package br.empresateste.testerelatorio.exception;

public class NotFoundException extends Exception {

	private static final long serialVersionUID = -6722261954538121254L;

    public NotFoundException(String msg) {
           super(msg);
    }

}
package br.empresateste.testerelatorio.model;

import java.io.*;


public class Aluno implements Cloneable, Serializable {

	private static final long serialVersionUID = 1L;
	
    private int idAluno;
    private String nome;
    private String matricula;
    private String situacaoFrequencia;
    private String situacaoPagamento;


    public Aluno () {

    }

    public Aluno (int idAlunoIn) {

          this.idAluno = idAlunoIn;

    }


    public int getIdAluno() {
          return this.idAluno;
    }
    public void setIdAluno(int idAlunoIn) {
          this.idAluno = idAlunoIn;
    }

    public String getNome() {
          return this.nome;
    }
    public void setNome(String nomeIn) {
          this.nome = nomeIn;
    }

    public String getMatricula() {
          return this.matricula;
    }
    public void setMatricula(String matriculaIn) {
          this.matricula = matriculaIn;
    }

    public String getSituacaoFrequencia() {
          return this.situacaoFrequencia;
    }
    public void setSituacaoFrequencia(String situacaoFrequenciaIn) {
          this.situacaoFrequencia = situacaoFrequenciaIn;
    }

    public String getSituacaoPagamento() {
          return this.situacaoPagamento;
    }
    public void setSituacaoPagamento(String situacaoPagamentoIn) {
          this.situacaoPagamento = situacaoPagamentoIn;
    }



    public void setAll(int idAlunoIn,
          String nomeIn,
          String matriculaIn,
          String situacaoFrequenciaIn,
          String situacaoPagamentoIn) {
          this.idAluno = idAlunoIn;
          this.nome = nomeIn;
          this.matricula = matriculaIn;
          this.situacaoFrequencia = situacaoFrequenciaIn;
          this.situacaoPagamento = situacaoPagamentoIn;
    }

    public boolean hasEqualMapping(Aluno valueObject) {

          if (valueObject.getIdAluno() != this.idAluno) {
                    return(false);
          }
          if (this.nome == null) {
                    if (valueObject.getNome() != null)
                           return(false);
          } else if (!this.nome.equals(valueObject.getNome())) {
                    return(false);
          }
          if (this.matricula == null) {
                    if (valueObject.getMatricula() != null)
                           return(false);
          } else if (!this.matricula.equals(valueObject.getMatricula())) {
                    return(false);
          }
          if (this.situacaoFrequencia == null) {
                    if (valueObject.getSituacaoFrequencia() != null)
                           return(false);
          } else if (!this.situacaoFrequencia.equals(valueObject.getSituacaoFrequencia())) {
                    return(false);
          }
          if (this.situacaoPagamento == null) {
                    if (valueObject.getSituacaoPagamento() != null)
                           return(false);
          } else if (!this.situacaoPagamento.equals(valueObject.getSituacaoPagamento())) {
                    return(false);
          }

          return true;
    }


    public String toString() {
        StringBuffer out = new StringBuffer(this.getDaogenVersion());
        out.append(&quot;\nclass Aluno, mapping to table aluno\n&quot;);
        out.append(&quot;Persistent attributes: \n&quot;); 
        out.append(&quot;idAluno = &quot; + this.idAluno + &quot;\n&quot;); 
        out.append(&quot;nome = &quot; + this.nome + &quot;\n&quot;); 
        out.append(&quot;matricula = &quot; + this.matricula + &quot;\n&quot;); 
        out.append(&quot;situacaoFrequencia = &quot; + this.situacaoFrequencia + &quot;\n&quot;); 
        out.append(&quot;situacaoPagamento = &quot; + this.situacaoPagamento + &quot;\n&quot;); 
        return out.toString();
    }


    public Object clone() {
        Aluno cloned = new Aluno();

        cloned.setIdAluno(this.idAluno); 
        if (this.nome != null)
             cloned.setNome(new String(this.nome)); 
        if (this.matricula != null)
             cloned.setMatricula(new String(this.matricula)); 
        if (this.situacaoFrequencia != null)
             cloned.setSituacaoFrequencia(new String(this.situacaoFrequencia)); 
        if (this.situacaoPagamento != null)
             cloned.setSituacaoPagamento(new String(this.situacaoPagamento)); 
        return cloned;
    }



    public String getDaogenVersion() {
        return &quot;DaoGen version 2.4.1&quot;;
    }

}
&lt;?xml version=&quot;1.0&quot; encoding=&quot;iso-8859-1&quot; ?&gt;
&lt;jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0"
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"&gt;

	&lt;f:view &gt;
		&lt;body&gt;
			&lt;h:form id="form"&gt;
				<br />
				<br />
				&lt;center&gt;		
					&lt;h:commandLink target="_blank" action="#{relatorioBean.geraRelatorioPassandoConexao}" value="Gerar relatório passando a conexão." /&gt;<br />
					&lt;h:commandLink target="_blank" action="#{relatorioBean.geraRelatorioPassandoResultSet}" value="Gerar relatório passando o ResultSet." /&gt;<br />
					&lt;h:commandLink target="_blank" action="#{relatorioBean.geraRelatorioPassandoListaDeObjetos}" value="Gerar relatório passando uma lista de objetos." /&gt;<br />
				&lt;/center&gt;

			&lt;/h:form&gt;
		&lt;/body&gt;
	&lt;/f:view&gt;
&lt;/jsp:root&gt;
&lt;?xml version=&quot;1.0&quot; encoding=&quot;iso-8859-1&quot; ?&gt;
&lt;jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0"
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"&gt;

	&lt;f:view&gt;
	
		&lt;h:outputText rendered="#{empty relatorioBean.saida}" value="Relatório não gerado. Consulte o Administrador do Sistema." /&gt;
	
		&lt;f:subview id="relatorio" rendered="#{not empty relatorioBean.saida}"&gt;
	
			&lt;iframe id="iframe" src="#{relatorioBean.saida}" width="99%"
				height="600px" style="min-height: 400px;"&gt; 
			&lt;/iframe&gt;
	
		&lt;/f:subview&gt;
		
	&lt;/f:view&gt;
&lt;/jsp:root&gt;
&lt;%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%&gt;

&lt;c:redirect url="index.jsf"/&gt;
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://java.sun.com/xml/ns/javaee"
	xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	id="WebApp_ID" version="2.5"&gt;

	&lt;display-name&gt;testeRelatorio&lt;/display-name&gt;

	&lt;welcome-file-list&gt;
		&lt;welcome-file&gt;default.jsp&lt;/welcome-file&gt;
	&lt;/welcome-file-list&gt;

	&lt;!-- Java Server Faces --&gt;
	&lt;servlet&gt;
		&lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
		&lt;servlet-class&gt;javax.faces.webapp.FacesServlet&lt;/servlet-class&gt;
		&lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
	&lt;/servlet&gt;

	&lt;servlet-mapping&gt;
		&lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
		&lt;url-pattern&gt;*.jsf&lt;/url-pattern&gt;
	&lt;/servlet-mapping&gt;

	&lt;context-param&gt;
		&lt;param-name&gt;javax.faces.CONFIG_FILES&lt;/param-name&gt;
		&lt;param-value&gt;/WEB-INF/faces-config.xml&lt;/param-value&gt;
	&lt;/context-param&gt;

	&lt;!-- Jsf - Manter Componentes para o Browser --&gt;
	&lt;context-param&gt;
		&lt;param-name&gt;javax.faces.STATE_SAVING_METHOD&lt;/param-name&gt;
		&lt;param-value&gt;client&lt;/param-value&gt;
	&lt;/context-param&gt;

	&lt;!-- Facelets --&gt;
	&lt;context-param&gt;
		&lt;param-name&gt;javax.faces.DEFAULT_SUFFIX&lt;/param-name&gt;
		&lt;param-value&gt;.jspx&lt;/param-value&gt;
	&lt;/context-param&gt;
	&lt;context-param&gt;
		&lt;param-name&gt;facelets.DEVELOPMENT&lt;/param-name&gt;
		&lt;param-value&gt;true&lt;/param-value&gt;
	&lt;/context-param&gt;
	&lt;context-param&gt;
		&lt;param-name&gt;facelets.REFRESH_PERIOD&lt;/param-name&gt;
		&lt;param-value&gt;1&lt;/param-value&gt;
	&lt;/context-param&gt;
	
&lt;/web-app&gt;
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL';

CREATE SCHEMA IF NOT EXISTS `academico` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci ;
USE `academico`;

-- -----------------------------------------------------
-- Table `academico`.`aluno`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `academico`.`aluno` (
  `id_aluno` INT NOT NULL AUTO_INCREMENT ,
  `nome` VARCHAR(120) NOT NULL ,
  `matricula` VARCHAR(20) NOT NULL COMMENT 'unique key' ,
  `situacao_frequencia` CHAR(1) NOT NULL COMMENT 'A - ATIVO\nI - INATIVO ' ,
  `situacao_pagamento` CHAR(1) NOT NULL COMMENT 'A - ADIMPLENTE\nI - INADIMPLENTE' ,
  PRIMARY KEY (`id_aluno`) ,
  UNIQUE INDEX `UNIQUE` (`matricula` ASC) )
ENGINE = InnoDB
COMMENT = 'Tabela de alunos da escola';


-- -----------------------------------------------------
-- Table `academico`.`professor`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `academico`.`professor` (
  `id_professor` INT NOT NULL AUTO_INCREMENT ,
  `nome` VARCHAR(120) NOT NULL ,
  `matricula` VARCHAR(20) NOT NULL ,
  `titulacao` VARCHAR(20) NOT NULL ,
  `situacao` CHAR(1) NOT NULL COMMENT 'A - ATIVO\nP - APOSENTADO\nL - LICENCIADO\nC - CEDIDO' ,
  PRIMARY KEY (`id_professor`) ,
  UNIQUE INDEX `UNIQUE` (`matricula` ASC) )
ENGINE = InnoDB
COMMENT = 'Tabela de professores dos alunos';


-- -----------------------------------------------------
-- Table `academico`.`professores_alunos`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `academico`.`professores_alunos` (
  `id_professor` INT NOT NULL ,
  `id_aluno` INT NOT NULL ,
  PRIMARY KEY (`id_aluno`, `id_professor`) ,
  INDEX `fk_aluno` (`id_aluno` ASC) ,
  INDEX `fk_professor` (`id_professor` ASC) ,
  CONSTRAINT `fk_aluno`
    FOREIGN KEY (`id_aluno` )
    REFERENCES `academico`.`aluno` (`id_aluno` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_professor`
    FOREIGN KEY (`id_professor` )
    REFERENCES `academico`.`professor` (`id_professor` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION);



SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;

&lt;faces-config
    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-facesconfig_1_2.xsd"
    version="1.2"&gt;
    
    &lt;application&gt;
    	&lt;view-handler&gt;com.sun.facelets.FaceletViewHandler&lt;/view-handler&gt;
    &lt;/application&gt;
    
	&lt;managed-bean&gt;
		&lt;description&gt;Bean para gerar relatórios.&lt;/description&gt;
		&lt;managed-bean-name&gt;relatorioBean&lt;/managed-bean-name&gt;
		&lt;managed-bean-class&gt;br.empresateste.testerelatorio.bean.RelatorioBean&lt;/managed-bean-class&gt;
		&lt;managed-bean-scope&gt;session&lt;/managed-bean-scope&gt;
	&lt;/managed-bean&gt;
	
	&lt;navigation-rule&gt;
		&lt;from-view-id&gt;*&lt;/from-view-id&gt;
		&lt;navigation-case&gt;
			&lt;from-outcome&gt;index&lt;/from-outcome&gt;
			&lt;to-view-id&gt;/index.jspx&lt;/to-view-id&gt;
		&lt;/navigation-case&gt;
		&lt;navigation-case&gt;
			&lt;from-outcome&gt;exibeRelatorio&lt;/from-outcome&gt;
			&lt;to-view-id&gt;/relatorio.jspx&lt;/to-view-id&gt;
		&lt;/navigation-case&gt;
	&lt;/navigation-rule&gt;

&lt;/faces-config&gt;
Criado 4 de maio de 2010
Ultima resposta 14 de mai. de 2010
Respostas 1
Participantes 2