Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > struts html:form with javascript for ajax

Reply
Thread Tools

struts html:form with javascript for ajax

 
 
eunever32@yahoo.co.uk
Guest
Posts: n/a
 
      02-27-2007
Hi

I have a struts (1.1) form

<html:form

<html:text
<html:text ...

</html:form>

All was well until I wanted to add an ajax field that would do auto-
complete.
Previously working example had
<input id="complete-field"

This was incompatible with the html:form tag and so I continued to use
<input

but when I submit the form the value of the input field is null

How can I modify my form so that I can use the javascript
functionality ?

Thanks

 
Reply With Quote
 
 
 
 
Lew
Guest
Posts: n/a
 
      02-28-2007
wrote:
> Hi
>
> I have a struts (1.1) form
>
> <html:form
>
> <html:text
> <html:text ...
>
> </html:form>
>
> All was well until I wanted to add an ajax field that would do auto-
> complete.
> Previously working example had
> <input id="complete-field"
>
> This was incompatible with the html:form tag and so I continued to use
> <input
>
> but when I submit the form the value of the input field is null


Does your input field have a name as well as an id?

Struts does some special magic to pull request parameters into its Form
classes. If you don't use its html: tag lib than you might need to make
explicit request.getParameter() calls in the Action class for those parameters.

- Lew
 
Reply With Quote
 
 
 
 
Shashanka.Rao@gmail.com
Guest
Posts: n/a
 
      02-28-2007
On Feb 28, 4:01 am, euneve...@yahoo.co.uk wrote:
> Hi
>
> I have a struts (1.1) form
>
> <html:form
>
> <html:text
> <html:text ...
>
> </html:form>
>
> All was well until I wanted to add an ajax field that would do auto-
> complete.
> Previously working example had
> <input id="complete-field"
>
> This was incompatible with the html:form tag and so I continued to use
> <input
>
> but when I submit the form the value of the input field is null
>
> How can I modify my form so that I can use the javascript
> functionality ?
>
> Thanks


Using Ajax you will be passing all the request parameters through GET
and the there is no form.submit() happening. This may be one of the
reasons. In that case only way to send these parameters is to build
the URL string with the request parameters. Look at the code below to
build your URL.

function retrieveURL(url,nameOfFormToPost) {

//convert the url to a string
url=url+getFormAsString(nameOfFormToPost);

//Do the AJAX call
if (window.XMLHttpRequest) {

// Non-IE browsers
req = new XMLHttpRequest();
req.onreadystatechange = processStateChange;
try {
req.open("GET", url, true);
} catch (e) {
alert("Server Communication Problem\n"+e);
}
req.send(null);
} else if (window.ActiveXObject) {
// IE

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


getFormAsString() is a "private" method used by the retrieveURL()
method. This will get all the form Elements and appends to the URL


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 format '/strutsaction.do&name=value'

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

//return the values
return returnString;
}

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP.NET and AJAX: JavaScript files from the Microsoft AJAX Library Nathan Sokalski ASP .Net 2 06-02-2007 12:07 AM
AJAX IDE and AJAX TOOL--The Release of JoyiStar AJAX WebShop 3 Beta minnie Java 1 12-13-2006 06:29 AM
Is it safe to point to Internet for locating struts DTD files in struts TLDs and XML files? Katie Wright Java 8 01-07-2005 03:37 PM
[Struts]output javascript in struts perform() sin Java 3 02-22-2004 08:27 AM
Struts Installation - missing struts.tld??? Jason Us Java 0 10-03-2003 11:36 PM



Advertisments