aspose file tools*
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
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: 2267
    
    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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get the value (a String[] array) from a Form Bean in a javascript?