Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts and JSON

 
Jay Abrahm
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Folks,

I'm not sure if this post goes in here but since it looked like a struts rendering issue that I didn't understand right I have posted it here.

I use struts 2 and have the following code in the action class



And the jsp page has the following call


The issues looks like the property tag is processes the data. Is there a way to prevent the property tag from doing this.
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't know whether this will works for you, but give it a try,
Just escape the single quote " ' ", while creating JSON object like,

 
Jay Abrahm
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Sagar.
Thats the problem. I would have escaped it in the struts code but unfortunately I am using a JSONObject.



Is there a way to escape it in the property tag ?
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jay Abrahm wrote:I would have escaped it in the struts code but unfortunately I am using a JSONObject.

Hmm, I thought that JSONObject class is developed by you as a helper class.
Maybe, we can repleace that JSON string with "\'", like




Jay Abrahm wrote:
Is there a way to escape it in the property tag ?

Never used Struts 2, but while exploring it <s:property> tag, I found something useful, its "escape" attribute itself, but its default value is "true", so don't think will it make any difference or not !!

Still use it and make its default value as a "false"

 
Jay Abrahm
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Issue resolved. Thanks and that was quick. I didn't notice your post coming in.

Yes, escape="false" did fix the escape for double quotes issue.



I still have another issue with the dojo not accepting the JSON (commented in the alerts above) but I guess the moderator might hack me down if I try to use this forum for that
 
Jay Abrahm
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just a side note. Even the JSON to dojo is working now fine. The nested object should also be a JSONObject.

I beginning to like JSON !!

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic