This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
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 Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Javascript string array to server" Watch "Javascript string array to server" New topic

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]}" >

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.

Consultant, Sima Solutions
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: Javascript string array to server
It's not a secret anymore!