The Artima Developer Community
Sponsored Link

Java Answers Forum
Struts with Ajax problem

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
vikas sheel gupta

Posts: 2
Nickname: vikassheel
Registered: Jan, 2006

Struts with Ajax problem Posted: Jan 4, 2006 4:49 AM
Reply to this message Reply
Advertisement
Hi
i need your help on ajax with struts
what i did is i have a text box and a select box with one button what i want to do is i enter a value in the textbox then after press the button that value shuld be inserted in the data base and also displayed in the select box .
i can able to update the data base and create response like this
***************************************************************

here is my action class:---
try
{
l_CatalougeImpl.addEcardCatagory(idField);// for data base insertion

String value_idField=idField.trim();//get the value here in the idField variable

StringBuffer l_stringBuffer= new StringBuffer();
l_stringBuffer.append("<catagory>");
l_stringBuffer.append("<CatagoryName>"+idField.trim()+"</CatagoryName& gt;");
l_stringBuffer.append("</catagory>");
addCatagory=true;

if(addCatagory)
{
response.setContentType("text/xml");
response.setHeader("Cache-Control", "no-cache");
response.getWriter().write("<Catagories>"+l_stringBuffer.toString()+"< /Catagories>");
}
else
{
response.setStatus(HttpServletResponse.SC_NO_CONTENT);
}


}catch(Exception e) {
return mapping.findForward("error");
}
return mapping.findForward("ecards.TestAJAX"); // it will forward to some jsp page as per struts-config.xml mapping
}
***************************************************************************** ****
Here is my JSP code:--
<%@page contentType="text/html" %>
<%@ taglib uri="../WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="../WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="../WEB-INF/struts-logic.tld" prefix="logic" %>
<html:html>
<head>
<title><bean:message key="Ecards.SendEcardForm.title"/></title>
<script>
var req;
var catagory;
function validate()
{
var idField=document.getElementById("card_name");
var url = "<%=request.getContextPath()%>/ajaximpl.do?id=" +idField.value;
if (window.XMLHttpRequest)
{
req = new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
req = new ActiveXObject("Microsoft.XMLHTTP");
}
req.open("GET", url, true);
req.onreadystatechange = callback;
req.send(null);
}
function callback()
{
if (req.readyState == 4)
{
//alert("Ajax response:"+req.responseText);
if (req.status == 200)
{
alert("update dom");
parseMessages();
}
else
{
alert("Ajax response:"+req.stutsText);
}
}
}
function parseMessages()
{
alert("inside the parsing Message");
var xml=req.responseXML;// Here i got the nulll value
alert("inside while loop");
var catagories=xml.getElementsByTagName("Catagories");
alert("catagories:--"+catago ries);
if(catagories !=null)
{
var catagoryId=catagories.childNodes;
if(catagoryId !=null)
{
catagory=catagoryId.getElementsByTagName("CatagoryName");
}
else
{
al ert("catagoryId has no value");
}
}
else
{
alert("catagories has no value");
}
}
alert("catagory value is :--"+catagory);
</script>
</head>
<body bgcolor="#FFFFFF">
<!-- Start: template code Vikas Sheel Gupta 22nd Dec 05 -->
<Center>
<table border="0" cellpadding="0" cellspacing="0" height='559' width='779'>
<tr>
<td valign="top" height='60'><jsp:include page="/header.jsp"/>
</td>
</tr>
<tr>
<td valign="top" height='439'>
<!-- Start : Vikas Sheel Gupta Code to display card and card contents -->
<html:form action="/ajaximpl">
<table>
<tr><td><bean:message key="Ecards.SendEcardForm.catagory" /></td>
<td>
<!-- code for card catagory-->
<logic:present name="Array_ecardlist" scope="request">
<html:select property='catagory' >
<html:options collection="Array_ecardlist" property="m_strCategoryId" labelProperty="m_strCategory_Name" />
</html:select>
</logic:present>
<!-- End of code for card catagory-->
</td>
</tr>
<tr><td><bean:message key="Ecards.SendEcardForm.card_name" /></td>
<td>
<html:text property="card_name" />
</td>
</tr>
<tr>
<td>
<html:button property="button" onclick="return validate()"><bean:message key="button.save"/></html:button>
</td>
</tr>
</table&g t;
</tr>
</table>
</html:form>
<!-- End : Vikas Sheel Gupta Code to display card and card contents -->
</td>
</tr>
<tr>
<td valign="top" height='60'><jsp:include page="/header.jsp"/></td>
</tr>
</table>
</Center>

<!-- End: template code-->
</body>
</html:html>

********************************** *****************************
Now my problem is when i call the parseMessages() function in java script then my req.responseXML is null i cant under stand why this happens
can u pls tell me why this happend
i shall be thank ful to you



Warm Regards
Vikas Sheel Gupta
09891424705
vikassheelgupta@rediffmail.com

Topic: Automatically inserting into MS Outlook email fields Previous Topic   Next Topic Topic: connection with wap gateway

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use