• 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

struts2 + json plugin problems

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm using the json plugin that comes with struts 2 (json-lib-2.1.jar) and trying to follow the website to set it up.

Here's my struts.xml



but I get this warning:
SEVERE: Unable to find parent packages json-default

Is there something else I'm supposed to do?
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What else have you done besides use the "extends" attribute? The json plugin isn't called "json-lib-2.1.jar"; that's just the JSON part--are you deploying the actual plugin?
 
Pj Casaro
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I actually didn't have the correct plugin! Ok, so I put in the right plugin, but still some problems.


However, I don't think the response is going from the RetrieveUser class to the javascript. I'm using firebug and no request gets sent.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Without knowing how you're making the request, it's impossible to help diagnose why it's not happening.
 
Pj Casaro
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes I understand, sorry I'm new to this so not too sure what things are relevant.

Here's everything I have.

1) The user clicks a link which triggers this action:


2) This just populates a list of users, and then automatically returns this result:


3) Here's my RetrieveUser class:


4) And my javascript file:


5) And finally my struts.xml:


In firebug, I can see that when I change an item in the select menu (triggering the onchange=fetchUser) I get this error in the javascript here:
that says "setting a property that has only a getter". I don't think the javascript is the problem because I've gotten this javascript to work before just not with this json plugin.
 
Pj Casaro
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok I found two problems.

The first is that I can't use the variable name "console" in my javascript when I'm using firebug I think. So I changed that.

The second is, now that I have a json result (finally!), I can't figure out how to parse it correctly.

Here's what it looks like (part of it):


The json is stored under jsonObject so I'm trying to access the user by saying "jsonObject.jsonModel[0]" but that's undefined. The problem is, it serialized the whole thing as an object and I don't know what "myusername" is going to be, so I can't just say jsonModel.myusername.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're getting an error in JavaScript but don't think it's in the JavaScript?

I'm pretty sure it is, *if* you're actually getting an error in the JavaScript. That's some pretty old-school JavaScript, too--yuck.

In any case, I don't understand why that would be an error you'd get in JavaScript itself, since JavaScript has no concept of getters and setters, but if it's a JavaScript error, it's most assuredly an error in JavaScript or the DOM with which it is interacting.
 
Pj Casaro
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code is from Struts 2 in action, a book I've been going through to try and learn struts.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Pj Casaro wrote:The json is stored under jsonObject so I'm trying to access the user by saying "jsonObject.jsonModel[0]" but that's undefined. The problem is, it serialized the whole thing as an object and I don't know what "myusername" is going to be, so I can't just say jsonModel.myusername.


Then it's probably not reasonable to serialize it like that, or you'll have to iterate over the properties to find out what the user name actually is.
 
Pj Casaro
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I figured as much and went ahead and changed it to serialize over my "User" object instead of the whole class. Now it almost works. However I do have maps as part of the user and the maps get converted to maps again in json, so I do have to iterate over keys at some point anyway. Is there a numkeys/size/length command for the number of keys in something?
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For JavaScript questions your best bet is to post in the HTML/JavaScript forum.
 
Pj Casaro
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK thanks! I solved all my issues relevant to this post. Thanks for all the help
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Glad you worked it out :)
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic