This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Struts and the fly likes How to get the value (a String[] array) from a Form Bean in a javascript? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to get the value (a String[] array) from a Form Bean in a javascript?" Watch "How to get the value (a String[] array) from a Form Bean in a javascript?" New topic
Author

How to get the value (a String[] array) from a Form Bean in a javascript?

Andre Lima
Greenhorn

Joined: Nov 10, 2010
Posts: 1
Here is a sample of the code I'm using:


JSP page:

<script type="text/javascript">
function submitForm(){
...
productArray = new Array(forms[0].elements['productList']); <--- this is NOT working. I'm getting a non-valid value (see attached screenshot, which contains the value displayed by alert function below)
alert (productArray);
...
}
</script>

<html:hidden property="'productList'" />


Form Bean:

public class ProductForm extends ActionForm {
private String[] productList;

public void setProductList(String[] productList) {
this.productList= productList;
}

public String[] getProductList() {
return productList;
}
...
}


Please any suggestions?


[Download productArray variable value displayed by alert().bmp] Download

Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2265
    
    3

Howdy, Andre. Welcome to JavaRanch!

Well, at a first glance, it looks like this code of yours won't work. You'll have to initialize your JavaScript array by iterating over your list (using the Struts' appropriate tags) and printing the values in each position of the JavaScript array.


Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to get the value (a String[] array) from a Form Bean in a javascript?