• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Why are there two types of methods for a particular operations in a project?  RSS feed

 
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a confusion regarding "Web Services",
Assume there is an 'Employee Management Web application'.
You have to perform a task that is to display all the records of employees from 'Employee' table.
you have written an 'EmployeeController' class where you are returning the "List" of employee objects to the browser through ModelAndView object, you even mentioned the "view" page name as well:



Now here it leaves me confused....the below written RESTful WS method performs the same task what the above method does but it sends the Employees objects in JSON format.
I want to know when does the above method has to execute and when this below one?
How relevant are both to each other?
Does every java based web project contains both types of methods for a particular operations?

I hope you have understood what i want to ask. Your help will be much appreciated. Thanks!
 
Saloon Keeper
Posts: 1800
74
Android Chrome IntelliJ IDE Java MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suspect that this codereturns object list named "employees" for the view named "page".
This view would most likely generate some document (often HTML or PDF) and a listing of objects as created by the view and template engine.

"/show/allEmployees" is the data rendered and ready for immediate presentation (usually via web browser) thanks to the logic provided by the view.

However this code:only returns the data without any extra markup. This data is most likely returned at a listing of JSON or XML objects.

The "allEmployees" call is a REST call which would be consumed by another program, maybe IOS, Android etc. This is only the data and nothing but the data.
Usually the consuming program has to add some extra display elements/design to the data before being displayed.

They are related in that they provide the same information, but in different ways for the consuming client.

Arun Singh Raaj wrote:Does every java based web project contains both types of methods for a particular operations?


No, as there is not always a reason do. Some data should not be consumed via REST for business reasons or other reasons.
Often most only program what they have to and nothing else. So you may see REST data or you may just regular data or you may see both.
Depends on what the project needs to provide to the end users/consumers.
 
Saloon Keeper
Posts: 9134
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends heavily on whether your application's presentation layer is mostly in the client or in the server.

For instance, it's possible to have an application that consists of a lot of static HTML pages, and every time you make a request the server builds a new web page. In this case, your server will mostly have methods of the first kind, that return a ModelAndView.

The other extreme is an application that consists of a single dynamic web page. In this case, the server has one method that returns a ModelAndView containing the entire client-side application, and all interaction with the server is done through AJAX requests that get handled by methods of the second kind, that return a JSON response body.

Most web applications are somewhere in the middle. They host a couple of different HTML pages, which to a varying degree communicate with the server with AJAX request.
 
Arun Singh Raaj
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for clearing that up... Stephan van Hulst, Pete Letkeman.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!