aspose file tools*
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 Spring in Action this week in the Spring 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
Author

Need to use Java ArrayList in Javascript

PankajKumar jaiswal
Greenhorn

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
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Eric
PankajKumar jaiswal
Greenhorn

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
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

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