Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
samir ware
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • 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
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic