Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Handling Lists of complex objects in Javascript/JSP

 
james frain
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Pie
Posts: 65226
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic