Ajax Talk - Asynchronous javascript and xml discussion board
 FAQ   Search    Usergroups      Register   Profile   Check your messages   Log in 
Signup now to enjoy a range of free membership advantages !!
Ajax Talk - Moderators Wanted
Ajax and Struts

 
Post new topic   Reply to topic    Ajaxtalk.com Forum Index -> AJAX Programmers Exchange
View previous topic :: View next topic  
Author Message
EMoriarty
New one
New one


Joined: 25 Jul 2006
Posts: 3

PostPosted: Tue Jul 25, 2006 3:11 pm    Post subject: Ajax and Struts Reply with quote

Hi, I have a problem with my struts application, I like use Ajax in the app.
but at the moment of including the HTML response fails.

This is the javascript complete code, if you need more, send me a mail.
Thanks in advance.


*/
function retrieveURL(url,nameOfFormToPost,capaC) {

//get the (form based) params to push up as part of the get request
alert(url);
capa = capaC;
alert(capa);
if(nameOfFormToPost != ""){
url=url+getFormAsString(nameOfFormToPost);
}
alert(url);
//Do the Ajax call
if (window.XMLHttpRequest) { // Non-IE browsers
req = new XMLHttpRequest();
req.onreadystatechange = processStateChange;
try {
req.open("GET", url, true); //was get
} catch (e) {
alert("Problem Communicating with Server\n"+e);
}
req.send(null);
} else if (window.ActiveXObject) { // IE

req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
alert(capa);
req.onreadystatechange = processStateChange;
req.open("GET", url, true);
req.send();
}
}
}

/*
* Set as the callback method for when XmlHttpRequest State Changes
* used by retrieveUrl
*/
function processStateChange() {

if (req.readyState == 4) { // Complete
if (req.status == 200) { // OK response

//alert("Ajax response:"+req.responseText);

//Use these span elements to update the page
replaceExistingWithNewHtml(req.responseText);

} else {
alert("Problem with server response:\n " + req.statusText);
}
}
}

/**
* gets the contents of the form as a URL encoded String
* suitable for appending to a url
* @param formName to encode
* @return string with encoded form values , beings with &
*/
function getFormAsString(formName){

//Setup the return String
returnString ="";

//Get the form values
formElements=document.forms[formName].elements;

//loop through the array , building up the url
//in the form /strutsaction.do&name=value

for ( var i=formElements.length-1; i>=0; --i ){
//we escape (encode) each value
returnString=returnString+"&"+escape(formElements[i].name)+"="+escape(formElements[i].value);
}

//return the values
return returnString;
}

/*
* Replace html elements in the existing (ie viewable document)
* with new elements (from the ajax requested document)
*/
function replaceExistingWithNewHtml(content){
capaContenedora = document.getElementById(capa);
if(capaContenedora){
alert("Replacing Element:"+capa);
capaContenedora.innerHTML = content;
} else {
alert("Element:"+capa+"not found in existing document");
}
}
Back to top
View user's profile Send private message
deejay
Forum Assistant
Forum Assistant


Joined: 17 May 2006
Posts: 78
Location: Netherlands

PostPosted: Fri Jul 28, 2006 9:47 am    Post subject: Hi EMoriarty, Reply with quote

Hi EMoriarty,

Welcome to this forum. As i have no experience with struts, i am sorry to say i can't help you.

Snyke maybe you know something ?

Rgds, D.J.
_________________
please correct me if i am wrong
seo-expertglobalwarming
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Snyke
Forum Assistant
Forum Assistant


Joined: 20 Jun 2006
Posts: 87
Location: Zurich

PostPosted: Fri Jul 28, 2006 11:03 am    Post subject: Reply with quote

This doesn't really have anything to do with Java Struts as far as I can see.
What you are doing is replacing the content of an element with the content delivered to you by an XHR. The only thing I noticed, flying over your code, is that
Code:
capa
is never defined in the last function
Code:
function replaceExistingWithNewHtml(content){
  capaContenedora = document.getElementById(capa);
  if(capaContenedora){
    alert("Replacing Element:"+capa);
    capaContenedora.innerHTML = content;
  } else {
    alert("Element:"+capa+"not found in existing document");
  }
}

which probably means that you have some sort of null-pointer.

What exactly is your problem anyway? Have you tried it with two static (non dynamically generated) documents?
_________________
[::[ Snyke.net ]::]
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
EMoriarty
New one
New one


Joined: 25 Jul 2006
Posts: 3

PostPosted: Fri Jul 28, 2006 11:33 am    Post subject: Reply with quote

capa is a global variable, a static document is returned, the problem is only in the jsp response, I don't know really why it isn't returned, I send the jsp response code to you, thanks again:


<table width="100%" align="center" border="0" cellpadding="0" cellspacing="0">
<html:form action="/UploadFormA.do" enctype="multipart/form-data" method="POST" target="Documentacion">
<html:hidden property="idAttributeInstance"/>
<html:hidden property="idAttribute"/>
<html:hidden property="idCatInstance"/>
<html:hidden property="idAttachment"/>
<html:hidden property="fileName"/>
<tr>
<td colspan="2" bgcolor="ff8400"><html:img page="/images/t.gif" width="1" height="30"/></td>
</tr>
<tr>
<td colspan="2" bgcolor="0099ff"><html:img page="/images/t.gif" width="1" height="10"/></td>
</tr>
<tr>
<td colspan="2"><html:img page="/images/t.gif" width="1" height="10"/></td>
</tr>
<tr>
<td class="naranja10"><strong>Adjuntar documento</strong></td>
<td align="right" class="naranja10">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="linea"><html:img page="/images/t.gif" width="1" height="1"/></td>
</tr>
<tr>
<td colspan="2"><html:img page="/images/t.gif" width="1" height="10"/></td>
</tr>
<tr>
<td valign="top" class="azul10c" align="center">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="14" class="azul10c">Documentaci&oacute;n adjunta</td>
</tr>
<tr>
<td>
<html:file size="60" property="uploadFile" onkeydown="document.forms[0].textoculto.focus();" onchange="analizaTextBox(this);" maxlength='256'/>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="2"><html:img page="/images/t.gif" width="1" height="5"/></td>
</tr>
<tr>
<td><table border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="14" class="azul10c">Descripci&oacute;n</td>
</tr>
<tr>
<td>
<html:text property="descripcion"/>
<input type="text" style='width:0px;' name="textoculto"/>
<%-- input oculto para quitar el foco al input file e impedir que se escriba en él,
así sólo permitiremos que se adjunte un archivo a traves del botón de examinar (input file)--%>
</td>
</tr>
</table></td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="2"><html:img page="/images/t.gif" width="1" height="5"/></td>
</tr>
<tr>
<td colspan="2" align="right">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td style="cursor:hand" onclick="window.close()">
<html:img page="/images/bot_cancelar.gif" width="58" height="17" hspace="10" border="0"/>
</td>
<td id="botonSubmit" onclick="if (document.forms[0].uploadFile.value.length > 0) {submitForm(); return false;}">
<html:img page="/images/bot_anadir.gif" width="50" height="17" border="0"/>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
</html:form>
</table>

If you see the action code and actionForm code, you ask me for it... Wink [/code]
Back to top
View user's profile Send private message
Snyke
Forum Assistant
Forum Assistant


Joined: 20 Jun 2006
Posts: 87
Location: Zurich

PostPosted: Fri Jul 28, 2006 11:39 am    Post subject: Reply with quote

So this is the page that is returned on XHR?
Did you try to use FireBug to see if the XHR and the response are actually being sent?
And once again I don't see why all you people try implementing the basic stuff, when there are so many good libraries out there: http://prototype.conio.net/
_________________
[::[ Snyke.net ]::]
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
EMoriarty
New one
New one


Joined: 25 Jul 2006
Posts: 3

PostPosted: Thu Aug 10, 2006 1:23 pm    Post subject: other problem in struts with ajax Reply with quote

Hi, I'm here again, but in this case my problem is that ajax doesn't interpret the jsp code and return this code whithout interpret, Somebody know anything about this kind of problem?
Back to top
View user's profile Send private message
Snyke
Forum Assistant
Forum Assistant


Joined: 20 Jun 2006
Posts: 87
Location: Zurich

PostPosted: Thu Aug 10, 2006 4:42 pm    Post subject: Reply with quote

Actually this is a problem with your Servlet container and not with Ajax itself.
_________________
[::[ Snyke.net ]::]
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Ajaxtalk.com Forum Index -> AJAX Programmers Exchange All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
 Advertisements
 XML & Copyright Notice 
    


Powered by phpBB © 2001, 2005 phpBB Group

What is according to Wikipedia: Ajax Web2.0 XML E4X


Link to our site:

  


del.icio.us digg spurl wists simpy newsvine blinklist furl blogmarks yahoo! myweb smarking ma.gnolia segnalo reddit fark technorati cosmos


Normal Bookmark


Partner Button Links:
Codecrunch.com: Webmaster Tutorials    One Ajax


Partner Text Links:
quomon | web20log | ajaxmatters | tableless | 456bereastreet | music charts | gift ideas | competitions | free xbox 360 | link trade ?


Credits:
it consultancy & project management lead generation zoekmachine optimalisatie steal these buttons seo expert