• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Handling Lists of complex objects in Javascript/JSP

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic