Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Spring and the fly likes How to use net.sf.json.spring.web.servlet.view.JsonView  ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "How to use net.sf.json.spring.web.servlet.view.JsonView  ?" Watch "How to use net.sf.json.spring.web.servlet.view.JsonView  ?" New topic
Author

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

samir ware
Ranch Hand

Joined: Jul 27, 2005
Posts: 192
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

Joined: Feb 05, 2001
Posts: 17249
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
samir ware
Ranch Hand

Joined: Jul 27, 2005
Posts: 192
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

Joined: Feb 05, 2001
Posts: 17249
    
    6

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
 
 
subject: How to use net.sf.json.spring.web.servlet.view.JsonView ?
 
Similar Threads
Configure spring controller to return json response
Spring MVC problem
Spring Book Question
getAsString method
Is my MVC design under RMI reasonable?