Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Andre Lima
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
Filename: productArray variable value displayed by alert().bmp
Description: productArray variable value displayed by alert() function
File size: 78 Kbytes
[Download productArray variable value displayed by alert().bmp] Download Attachment
 
Roberto Perillo
Bartender
Posts: 2273
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I will open the floodgates of his own worst nightmare! All in a tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!