Disparar eventos JSP

3 respostas
almarti

Estou utilizando JSP.

Construi um metodo que retorna uma série de arrays. Gostaria de utilizar estes arrays em uma paginação. Assim, tenho uma página chamada Corpo_grid.jsp que é quem controi os arrays e outra chamada grid.jsp que carrega-se pelo conteudo dos arrays disparados. O que eu preciso fazer é o seguinte: atualizar a pagina grid.jsp disparando um array segundo o momento, por exemplo. Botão nex a primeira vez, deve disparar o array[1], Botão nex a segunda vez, deve disparar o array[2], e assim por diante.

Utilizando o metodo=post eu preciso enviar uma action=página.jsp. Não posso fazer isto, ou então estaria refazendo o metodo, o que eu não preciso pois já possuo o que eu preciso nos arrays. É possível, ao inves de dispara no action uma página, fosse disparado um evento (função)?

3 Respostas

quebrado

Use uma das interfaces ServletRequestListener ou HttpServletSessionAttributeListener, de uma procurada no google que vc acha mais referencias sobre elas e qual delas ira se enquadrar no que vc precisa.
fui… 8)

quebrado

puts! esqueci da principal interface neste seu caso HttpSessionBindingListener :shock:

almarti

Pesquisei, mas não sei se resolveria o meu caso. Vamos por partes:

Estou construindo uma grid dinamica. Seghue o Código:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ page import = "java.io.*,java.util.*,java.net.*,java.sql.*,javax.servlet.*,javax.servlet.http.*"
%>
<jsp:useBean id ="cnx" class="util.conexao"/>
<jsp:useBean id ="rows" class="util.GetRowCount"/>


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title></title>
</head>
<body>
<%
		try{
		String strSql="SELECT * FROM tab_tipo_logradouro";//request.getParameter("sql");
		//	Conexao1 cnx = new Conexao1();
		
						
			int nRows = 2;//Integer.parseInt(request.getParameter("rows"));
			
			int nBotao = 0;
			
			ResultSet rs = cnx.ExecutaSQL(strSql);
			
			ResultSetMetaData nCols = rs.getMetaData();
			
			int nPaginas = 1;
			
			int intTotalRows=3;
			
//			if(nRows < (intTotalRows+1))
//					nPaginas = 1;
//				else
					nPaginas =  (Math.abs(intTotalRows/nRows))+1;
		String retorno[];
		retorno = new String[nRows];

		//System.out.print(nCols.getColumnCount());
rs.first();

for(int j = 0;j<(nPaginas);j++)
{
	//if (rs.isLast()==false)
	//{
	
	
	retorno[j] = "";
	
	retorno[j] = retorno[j] + "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'> " + "\n";
	retorno[j] = retorno[j] + "<html>" + "\n";
	retorno[j] = retorno[j] + "<head>" + "\n";
	retorno[j] = retorno[j] + "<script type='text/javascript' src='../js/Bs_Misc.lib.js'></script> " + "\n";
	retorno[j] = retorno[j] + "<script type='text/javascript' src='../js/Bs_DataGrid.class.js'></script> " + "\n";
	retorno[j] = retorno[j] + "<link rel='stylesheet' href='../css/style1.css'> " + "\n";

	retorno[j] = retorno[j] + "<script type='text/javascript'> " + "\n";
	retorno[j] = retorno[j] + "function init() { " + "\n";
	retorno[j] = retorno[j] + "myGrid = new Bs_DataGrid('myGrid'); " + "\n";
	retorno[j] = retorno[j] + "myGrid.bHeaderFix = false; " + "\n";

	int i = 0;
	String strArray="";
	String strTitulo="";
	String tretorno="";

	for(int X = 0;X<(nRows);X++)//while(rs.next())
	{
	
	
		//rs.first();
		strTitulo="";
		for (i=0;i<(nCols.getColumnCount());i++)
		{
			if (nCols.getColumnCount()==1)
			{
				strArray="'"+ rs.getString(nCols.getColumnName(i+1))+"'";
				strTitulo = "{text:'" + nCols.getColumnName(i+1) + "', align:'center'}";
			}
			else{
				if (i==nCols.getColumnCount()-1)
				{
				strArray=strArray+"'"+ rs.getString(nCols.getColumnName(i+1))+"'";
				strTitulo = strTitulo +	"{text:'" + nCols.getColumnName(i+1) + "', align:'center'}";
				}
				else{
					strArray=strArray+"'"+ rs.getString(nCols.getColumnName(i+1))+"',";
					strTitulo = strTitulo +	"{text:'" + nCols.getColumnName(i+1) + "', align:'center'},";
				}
			}
		}
		
		
		
		//Retorna o ponteiro do contador para zero
		tretorno = tretorno + "data[data.length] = new Array(" + strArray + "); " + "\n";
		i=0;
		strArray="";
		
		if (rs.isLast()==false )
			{
			rs.next();
			}
		else
		{
			X++;
		}
			
	
	}
	retorno[j] = retorno[j] + "var header = new Array("+strTitulo+"); " + "\n";
	retorno[j] = retorno[j] + "var data   = new Array(); " + "\n";
	retorno[j] = retorno[j] + tretorno;
	retorno[j] = retorno[j] + "myGrid.setHeaderProps(header); " + "\n";
	retorno[j] = retorno[j] + "myGrid.setData(data); " + "\n";
	retorno[j] = retorno[j] + "myGrid.drawInto('myGridDiv'); " + "\n";
	retorno[j] = retorno[j] + "} " + "\n";
	retorno[j] = retorno[j] + "</script> " + "\n";
	retorno[j] = retorno[j] + "</head> " + "\n";

	retorno[j] = retorno[j] + "	<body onLoad='init();'> " + "\n";

	retorno[j] = retorno[j] + "	<div id='myGridDiv'></div> " + "\n";

	retorno[j] = retorno[j] + "</body> " + "\n";
	
	
	
	

	}	
	
	cnx.FechaConexaoBD();
	
		%>

<P > 
<TABLE style="BORDER-COLLAPSE: collapse" borderColor=#808080 cellSpacing=0 
cellPadding=2 width="80%" border=1>
  
  <TR>
    <TD>
    </TD>
  </TR>
  <TR>
    <TD>
    <iframe src="grid.jsp?sql=<%out.print(retorno[nBotao]); %>" frameborder="1" name="frame1" width="100%" height="100%" border=0 marginwidth="1" marginheight="1" scrolling="yes"></iframe>
    </TD>
   </TR>
  <TR>
    <TD>

<%
		}
catch(Exception e)
{
	out.print( ""+ e);

}


%>
      <TABLE style="WIDTH: 107px; BORDER-COLLAPSE: collapse; HEIGHT: 25px" 
      borderColor=#808080 cellSpacing=0 cellPadding=2 width=107 border=1>
        
        <TR>
        <form name="form1" method="post" action="grid">
          <TD><INPUT type=button value="|<" name=bt_primeiro></TD>
          <TD><INPUT type=button value="< " name=bt_anterior></TD>
          <TD><INPUT type=button value="> " name=bt_proximo></TD>
          <TD><INPUT type=button value=">|" name=bt_ultimo></TD></TR></TABLE></TD></TR></TABLE></P>
        </form>
</body>
</html>

O que eu preciso?

em






eu precisaria, conforme o o botão clicado, alterar


Isto porque o array retorno[nBotao] conteria o que eu preciso para a paginação da grid.

Criado 11 de janeiro de 2007
Ultima resposta 11 de jan. de 2007
Respostas 3
Participantes 2