Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the 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?  RSS feed

 
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: 80 Kbytes
 
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!