aspose file tools
The moose likes Struts and the fly likes Javascript string array to server Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Frameworks » Struts
Reply Bookmark "Javascript string array to server" Watch "Javascript string array to server" New topic
Author

Javascript string array to server

basha khan
Ranch Hand

Joined: Jan 26, 2002
Posts: 516
Anybody know how to send a javascript string array(or values) to server in struts?.


In Detail
[ January 18, 2006: Message edited by: basha khan ]
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
First of all, the tag:

<html:hidden property = "stringsSelected"/>

Will not work if stringsSelected is an array. If you use the view Source function of your browser, you will see that the rendered code is not what you expect.

You would need to write something like this:
<c:forEach var="element" items="${myForm.stringsSelected}" varStatus="status">
<input type="hidden" name="stringsSelected" value="${myForm.stringsSelected[status.index]}" >
</c:forEach>

This will generate one hidden tag for each element of the array. If you wish to replace this array with a javaScript array, you will have to create a loop and replace them one element at a time. Something like this:

var elements = document.getElementsByName("stringsSelected");
for (var i=0;i<elements.length;i++) {
elements[i].value = myJavaScriptArray[i];
}

This assumes the arrays are of the same length.


Merrill
Consultant, Sima Solutions
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Javascript string array to server
 
Similar Threads
Java String Array variable in JSP to a javascript function?
sorting table data
Javascript array to server
passing java string array to javascript
how to acces arraylist in javascript