File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes HTML, CSS and JavaScript and the fly likes Handling Lists of complex objects in Javascript/JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Handling Lists of complex objects in Javascript/JSP" Watch "Handling Lists of complex objects in Javascript/JSP" New topic

Handling Lists of complex objects in Javascript/JSP

james frain
Ranch Hand

Joined: Apr 06, 2011
Posts: 36

This is my server side class

the two fields have getters and setters. On my JSP side I have a var declared as

My Struts Action has a getter called getDefinitions which gets called and returns a list of DefinitionT objects.
In my JS I have the following code

Firstly I was trying to figure out how to get the number of objects in the list but g_definitions.size is "Undefined" If I try to access g_definitions[0].value it is also undefined. How do I handle this list properly?
Eric Pascarello

Joined: Nov 08, 2001
Posts: 15385

This var g_definitions="<s:property value="definitions"/>"; is storing it into a string. View page source and look at what is sent to the browser.

What do you think you are doing by referencing it with g_definitions[i] ?

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63866

Yup, the first step to debugging any issue like this is to look at what's actually being sent to the browser. If you expected a list to be rendered, you'd see that it is not.

You either need to write the JSP code to create the JavaScript equivalent of the list, or (and this is a great cheat) flatten the list to JSON.

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: Handling Lists of complex objects in Javascript/JSP
It's not a secret anymore!