• 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
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

How to use net.sf.json.spring.web.servlet.view.JsonView ?

 
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Ranchers
I am trying to use net.sf.json.spring.web.servlet.view.JsonView as my default view. I read out some code examples on the net though was not able to understand how Spring identifies to which view it should forward the control to ?
As per my understanding net.sf.json.spring.web.servlet.view.JsonView is used if we want to convert model to JSON . net.sf.json.spring.web.servlet.view.JsonView will convert the model to JSON automatically and will forward it to the same view from where request came from . Though If I hit the controller from page X.jsp , convert the datamodel to JSON and now wish to forward this JSON to Y.jsp how spring will handle this using net.sf.json.spring.web.servlet.view.JsonView? Is it the restriction that JSON data will be forwarded ONLY to the view from which it came from if we use net.sf.json.spring.web.servlet.view.JsonView ?
Any link, white paper will greatly be appriciated.
Thanks
Samir
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. JSON itself is the view returned. And since there is no new view name, it uses the incoming request URL as the URL that it returns the JSON data to.

If you just want a second page to show with that data, you don't use the JsonView, you just add your data to the Model and return a view String, if you are using the InternalResourceViewResolver.

Meaning the purpose of JsonView is not to forward to a different page.

Mark
 
samir ware
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Mark,
Thanks a lot for the reply. I do understand the points which you mentioned in your last post and that really helped to clarify the concept. Though if I go for any other kind of view, I will loose all the out of the box JSON conversion made by jsonView.
Thats the reason I was looking out for any option that could make me free from JSON conversion part as well as allow me to forward the response to some other view.
Thanks
Samir
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That is exactly what Spring 3.0's RESTful WebServices are used for. You can have one method that supports Web Pages, JSON, xml, RSS or Atom feeds.

Mark
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic