wood burning stoves 2.0*
The moose likes HTML, CSS and JavaScript and the fly likes Need to use Java ArrayList in Javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Need to use Java ArrayList in Javascript" Watch "Need to use Java ArrayList in Javascript" New topic

Need to use Java ArrayList in Javascript

PankajKumar jaiswal

Joined: Aug 13, 2006
Posts: 17
Hi All,
I am working on Struts and my jsp page has an ArrayList of Objects(Privilege having PrivilegeName and PrivilegeCategory).
Now i have a dropdown of Privileges Category and whenever i select any category i have to display the names of the privileges it have. Now the problem is i dont know how to access the ArrayList into javascript and then how to iterate it so that i can get the category name and then get the list of privileges name for that category and then show it into jsp page.
Pls help.
Eric Pascarello

Joined: Nov 08, 2001
Posts: 15376
You would have to write the arraylist to the page in a way JavaScript could understand. Read this article: http://www.javaranch.com/journal/200510/Journal200510.jsp#a1

PankajKumar jaiswal

Joined: Aug 13, 2006
Posts: 17
I didn't understand. Pls make it more clear.
Thanks in Advance !!
Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211

Javascript cannot access any Java objects directly.
You need to convert the list into some kind of String value (comma separated, xml, JSON etc), which you will need to convert back into a Javascript Array or object on the client (browser).

The future is here. It's just not evenly distributed yet. - William Gibson
Consultant @ Xebia. Sonny Gill Tweets
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 60050

Did you read the article Eric linked to?

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
I agree. Here's the link: http://aspose.com/file-tools
subject: Need to use Java ArrayList in Javascript
Similar Threads
help regarding html select
JSP/JSF/Javascript popup window
I'm totally confused over this one....
how to fill a combobox with values from objects in an ArrayList...
array list into jsp page