wood burning stoves*
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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
Author

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

Joined: Nov 08, 2001
Posts: 15376
    
    6

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] ?

Eric
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

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] [Bear's FrontMan] [About Bear] [Books by Bear]
 
jQuery in Action, 2nd edition
 
subject: Handling Lists of complex objects in Javascript/JSP
 
Similar Threads
passing javascript array from jsp to servlet
How to pass Object to Javascript function in JSP
How to set value to session in external js file
JSP code not working properly
putting values from ArrayList to optionlist/dropdownlist