File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Javascript string array to server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
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://aspose.com/file-tools
 
subject: Javascript string array to server