Prototype e Servlet

4 respostas
robinsonbsilva

Senhores, eu tenho uma tela que possui três combos, e elas são carregadas tendo como parâmetro a combo anterior selecionada, veja :

cboCliente (todos clientes ativos já vem carregados)
cboCircuito (carrega apenas os circuitos do cliente selecionado acima)
cboRepetidora (carrega apenas as repetidoras do cliente selecionado acima)

Aí para isso eu criei uma Servlet, e nela eu passo os parametros necessários.
O problema que ocorre, é que funciona perfeitamente para carregar a cboCircuito, agora quando seleciono um item nesta combo consequentemente deveria carregar a cboRepetidora mas nada ocorre.

Abaixo está um trecho da .jsp e o fonte da Servlet

&lt;label for="Cliente"&gt;&lt;strong&gt;*&lt;/strong&gt;Cliente<br>
               &lt;html:select property="idPj" styleId = "idPj" tabindex="1" style="width: 400px" value='${dto.pj.idPj}' onchange="new Ajax.Updater('selectBoxCircuito', '/controlIp/AjaxServlet?action=circuito&idPj='+ this.value);"&gt;
                  &lt;html:option value="-1"&gt;Selecione uma opção&lt;/html:option&gt;
                  &lt;html:options collection="listPjs" property="idPj" labelProperty="nomeFantasia"/&gt;
               &lt;/html:select&gt;  
            &lt;/label&gt;
            
			&lt;div id="selectBoxCircuito"&gt;
				&lt;label for="Circuito"&gt;&lt;strong&gt;*&lt;/strong&gt;Circuito:<br>
					&lt;html:select property="idCircuito" styleId = "idCircuito" tabindex="2" style="width: 400px" value='${dto.circuito.idCircuito}' onchange="new Ajax.Updater('selectBoxRepetidora', '/controlIp/AjaxServlet?action=repetidora&idPj=205');"&gt;
						&lt;html:option value="-1"&gt;Selecione uma opção&lt;/html:option&gt;
						&lt;html:options collection="listCircuitos" property="idCircuito" labelProperty="designacao"/&gt;
					&lt;/html:select&gt;
				&lt;/label&gt;
			&lt;/div&gt;

			&lt;div id="selectBoxRepetidora"&gt;
				&lt;label for="Repetidora"&gt;&lt;strong&gt;*&lt;/strong&gt;Repetidora:<br>
					&lt;html:select property="idPonto" styleId = "idPonto" style="width: 400px" tabindex="3" value='${dto.repetidora.idPonto}'&gt; 
						&lt;html:option value="-1"&gt;Selecione uma opção&lt;/html:option&gt;
						&lt;html:options collection="listRepetidoras" property="idPonto" labelProperty="descricao"/&gt;  
					&lt;/html:select&gt;  
				&lt;/label&gt;
			&lt;/div&gt;
package br.com.unitelco.servlet;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.com.unitelco.dto.CircuitoDTO;
import br.com.unitelco.dto.RepetidoraDTO;
import br.com.unitelco.exceptions.DAOException;
import br.com.unitelco.utils.ComboUtils;

public class AjaxServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public AjaxServlet() {
		super();
	}

	public void init() throws ServletException {
	}

	public void destroy() {
		super.destroy();
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		ComboUtils combo = new ComboUtils();
		String action = request.getParameter("action");
		response.setCharacterEncoding("ISO-8859-1");

		int idPj = 0;
		if (request.getParameter("idPj") != null) {
			idPj = Integer.parseInt(request.getParameter("idPj"));
		}

		if ("circuito".equals(action)) {

			RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/jsp/ajax/circuitoCliente.jsp");

			try {
				ArrayList&lt;CircuitoDTO&gt; rows = (ArrayList&lt;CircuitoDTO&gt;) combo.Circuitos(request, idPj);
				request.setAttribute("listCircuitos", rows);
			} catch (DAOException e) {
				request.setAttribute("erro", e.getMessage());
			}

			dispatcher.forward(request, response);

		} else if ("repetidora".equals(action)) {

			RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/jsp/ajax/repetidoraCliente.jsp");
			
			try {
				ArrayList&lt;RepetidoraDTO&gt; rows = (ArrayList&lt;RepetidoraDTO&gt;) combo.Repetidoras(request, idPj);
				request.setAttribute("listRepetidoras", rows);
			} catch (DAOException e) {
				request.setAttribute("erro", e.getMessage());
			}

			dispatcher.forward(request, response);
		}

	}
}

4 Respostas

ramilani12

Humm…na sua Servlet estes JSP`s retornam XML´s?

robinsonbsilva

Não… a única coisa que a servlet faz mesmo é popular um list!

ramilani12

E como vc repassa dos dados novamente para Ajax?
A ideia é vc construir um Servlet que gere um XML para ti.

robinsonbsilva

Então, eu dou um dispatcher para um jsp e nele eu faço a rotina para popular a combo.

o meu problema mesmo é isso aqui:

&lt;label for="Cliente"&gt;&lt;strong&gt;*&lt;/strong&gt;Cliente<br>
   &lt;html:select property="idPj" styleId = "idPj" tabindex="1" style="width: 400px" value='${dto.pj.idPj}' onchange="new Ajax.Updater('selectBoxCircuito', '/controlIp/AjaxServlet?action=circuito&idPj='+ this.value);"&gt;
      &lt;html:option value="-1"&gt;Selecione uma opção&lt;/html:option&gt;
      &lt;html:options collection="listPjs" property="idPj" labelProperty="nomeFantasia"/&gt;
   &lt;/html:select&gt;  
&lt;/label&gt;

&lt;div id="selectBoxCircuito"&gt;
   &lt;label for="Circuito"&gt;&lt;strong&gt;*&lt;/strong&gt;Circuito:<br>
      &lt;html:select property="idCircuito" styleId = "idCircuito" tabindex="2" style="width: 400px" value='${dto.circuito.idCircuito}' onchange="new Ajax.Updater('selectBoxRepetidora', '/controlIp/AjaxServlet?action=repetidora&idPj=121');"&gt;
          &lt;html:option value="-1"&gt;Selecione uma opção&lt;/html:option&gt;
          &lt;html:options collection="listCircuitos" property="idCircuito" labelProperty="designacao"/&gt;
      &lt;/html:select&gt;
   &lt;/label&gt;
&lt;/div&gt;

na segunda combo ele não dispara a servlet…!!

Criado 24 de setembro de 2008
Ultima resposta 24 de set. de 2008
Respostas 4
Participantes 2