Jsp+Ajax+Alert

0 respostas
victormenegusso

Olá galera, eu tenho em um servidor Jboss um Portlet que recebe dados e quando é feito um submit os dados são enviados por ajax,, ai o portlet retorna para o Jsp uma menssagem de ( ok, erro), essa msg vem ok, mas gostaria que fosse um alert essa msg.
segue o codigo

Jsp
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<portlet:defineObjects/>
<script type="text/javascript">
 [b]function ajaxSubmitAPE_12_32_24_618(url,target,params,effects)
 {	 
   new Ajax.Updater(target, url, {method: 'GET', asynchronous:true,parameters:params});
 }[/b]
 </script>
<div style="height:800px; width:600px;background-color: -1";>

<form method='post' name="myformww" action="" onsubmit="ajaxSubmitAPE_12_32_24_618('<%=renderResponse.createResourceURL()%>','APE_12_32_24_618', Form.serialize(this),true); return false;"><!-- ******************************************************************************************** -->
	<input type="text" name="APA_12_32_46_186"  
	style=" width :200px; height :30px;
	position:absolute; margin-left: 180px;margin-top: 50px;
	FONT-FAMILY: ''; font-size:12px;
	font-style: ; font-weight: ; color:rgb(); "
	value="">

<!-- ******************************************************************************************** -->
<label 	name="APA_12_32_46_186" style="width :200px; height :30px;
	position:absolute; margin-left: 10px;margin-top: 50px;
	font-size:12px;
	font-style: ; font-weight: ; color:rgb(); ">
	Nome
</label>
	<!-- ******************************************************************************************** -->
<input type="button" name="cancel" 
	style="white; width :113px; height :32px;
	position:absolute; margin-left: 310px;margin-top: 760px;
	font-size:12px;
	font-style: ; font-weight: ; color:rgb; "
	value=Cancel onclick="AjaxRequest('<portlet:actionURL></portlet:actionURL>','', form.serialize(this),true)">
	<!-- ******************************************************************************************** -->
<input type="submit" name="Ok" 
	style="white; width :113px; height :32px;
	position:absolute; margin-left: 440px;margin-top: 760px;
	font-size:12px;
	font-style: ; font-weight: ; color:rgb; "
	value=OK onclick="AjaxRequest('<portlet:actionURL></portlet:actionURL>','', form.serialize(this),true)">
	<!-- ******************************************************************************************** -->
	<div name="APA_12_32_40_602" style=" width :100px; height :40px;
	position:absolute; margin-left: 18px;margin-top: 100px;
	FONT-FAMILY: ''; font-size:12px;
	font-style: ; font-weight: ; color:rgb();"> 
	<input type="checkbox" name="APA_12_32_40_602" 
	value="true">FUma</div>

<!-- ******************************************************************************************** -->
<input type="button" name="cancel" 
	style="white; width :113px; height :32px;
	position:absolute; margin-left: 310px;margin-top: 760px;
	font-size:12px;
	font-style: ; font-weight: ; color:rgb; "
	value=Cancel onclick="AjaxRequest('<portlet:actionURL></portlet:actionURL>','', form.serialize(this),true)">
	<!-- ******************************************************************************************** -->
<input type="submit" name="Ok" 
	style="white; width :113px; height :32px;
	position:absolute; margin-left: 440px;margin-top: 760px;
	font-size:12px;
	font-style: ; font-weight: ; color:rgb; "
	value=OK onclick="AjaxRequest('<portlet:actionURL></portlet:actionURL>','', form.serialize(this),true)">
	<!-- ******************************************************************************************** -->
	<input type="text" name="APA_12_32_28_666"  
	style=" width :200px; height :30px;
	position:absolute; margin-left: 180px;margin-top: 150px;
	FONT-FAMILY: ''; font-size:12px;
	font-style: ; font-weight: ; color:rgb(); "
	value="">

<!-- ******************************************************************************************** -->
<label 	name="APA_12_32_28_666" style="width :200px; height :30px;
	position:absolute; margin-left: 10px;margin-top: 150px;
	font-size:12px;
	font-style: ; font-weight: ; color:rgb(); ">
	Idade
</label>
	<!-- ******************************************************************************************** -->
<input type="submit" name="Ok" 
	style="white; width :113px; height :32px;
	position:absolute; margin-left: 440px;margin-top: 760px;
	font-size:12px;
	font-style: ; font-weight: ; color:rgb; "
	value=OK onclick="AjaxRequest('<portlet:actionURL></portlet:actionURL>','', form.serialize(this),true)">
	
</form>
</div> 
[b]<div id="APE_12_32_24_618"></div>[/b] // aqui que o Ajax coloca a msg

import java.io.IOException;
import java.sql.SQLException;
import java.io.PrintWriter;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.Event;
import javax.portlet.EventRequest;
import javax.portlet.EventResponse;
import javax.portlet.GenericPortlet;
import javax.portlet.PortletException;
import javax.portlet.PortletRequestDispatcher;
import javax.portlet.PortletSecurityException;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.portlet.ResourceRequest;
import javax.portlet.ResourceResponse;
import javax.portlet.UnavailableException;
public class P1 extends GenericPortlet {
	//Atributos
	private BD banco = new BD();
	private String APA_12_32_46_186= "";
	private Boolean APA_12_32_40_602;
	private int APA_12_32_28_666;
	private String Erro = "";
	@Override
	protected void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException, UnavailableException {
		response.setContentType("text/html"); 
		request.setAttribute("Erro", this.Erro);
		PortletRequestDispatcher pagina = getPortletContext().getRequestDispatcher("/p1.jsp");
		pagina.include(request, response);
	}
	public void serveResource(ResourceRequest request, ResourceResponse resp) throws PortletException, PortletSecurityException, IOException {
		try{
			this.APA_12_32_46_186 = request.getParameter("APA_12_32_46_186");
			this.APA_12_32_40_602 = Boolean.parseBoolean(request.getParameter("APA_12_32_40_602"));
			this.APA_12_32_28_666 = Integer.parseInt( request.getParameter("APA_12_32_28_666"));
			[b]this.Verificacao()[/b];//Procura os erros
		}catch (Exception e) {
			this.Erro = "Tipo de dado Invalido";}
		resp.setContentType("text/html");
		PrintWriter writer = resp.getWriter();
		//writer.print("<script type=\"text/javascript\">alert(\"Custom onError handler\");</script>");
		[b]writer.print(this.Erro);[/b] //escreve o e erro
		writer.close();
		this.Erro ="";
	}
          ......................
}

vlw

Criado 17 de junho de 2010
Respostas 0
Participantes 1