Advice on using MVC Spring framework with client side view - spring

I wanted some tips regarding the following problem, from the Java experts in this forum:
I am currently working on a web application with lot of SQL transactions based on MVC architecture. Is is possible to have the view completely developed and hosted at the client side, with the controller and model at the server?
The idea is to represent data in a way desired by end users. So, the View is developed (adhering to some defined standards) by the end users itself, where the controller and model remains the same.
I think it is possible with the MVC Spring framework, but don't know how exactly.
Thanks.
Shaun

Is is possible to have the view completely developed and hosted at the client side, with the controller and model at the server?
What do you mean by this? Well, you may build HTML on client with Java Script by sending ajax requests for data to controller, but it's not the way Spring MVC designed for. For that you probably will need something like DWR

Related

Spring Boot REST architecture

Lately i've been developing a Spring boot application with Angular 5 frontend and i got a little confused about the architecture of it. I was taught to write repositories, services and controllers in spring and to follow the MVC pattern. I started to write the documentation for the app and im trying to describe the arhitecture. So as i think View is the Angular app, C consists of the controller classes, and i described the third layer as buisniss logic which consists of the entity and service classes. But what is the Model really? Did i manage to follow the MVC pattern? In addition i have a controlleradvice, exception classes and security classes that make the authentication and authorization using jwts, but i guess these classes totally stay out from the MVC.
I've searched for the explanation but didnt seem to find it. Could someone please explain this to me? Thank you!
UPDATE
So basically what i dont understand is how the spring classes + angular meet the requirements of the MVC pattern
For example this is one of the first diagrams on the internet when you search for spring layers but as i see these are different from MVC
enter image description here
As mentioned in the comments, both your backend with Spring boot and your frontend with Angular can be seen as different applications, each following the Model-View-Controller design pattern.
You also posted a screenshot of the three-tier architecture. This type of architecture only tells you about how to structure your code. Typically, the MVC-part of your application is within the presentation layer (in your screenshot it's called the web layer).
So, if you would look at your backend application, you can identify the following parts:
Data tier/Repository layer: Repositories
Business tier/Service layer: Services
Presentation tier/Web layer: Model-View-Controller + Dispatcher
Model: Whatever you expose within your services (could be DTOs)
View: JSON structure/mapping
Controller: Spring controllers
And for your frontend you could identify them as well:
Data tier: HTTP calls
Business tier: Angular services
Presentation tier: Components + Router
Model: Whatever you expose within your services (probably a similar structure as the one you expose in your backend)
View: Templates
Controller: Components
This is a bit oversimplified though, and probably not something everyone will agree with.
I am working on the same project with angular as a frontend and spring boot as a backend, and i am still a little bit confused about it's architecture just like you, but i finally had to adopt the MVC model since i am actually using controllers, defining models and rendering views (the json results).
Obviously your front end uses a CBA (component based architecture and your backend is using an MVC pattern since spring MVC is embedded inside spring boot so it actually uses the same logic.
here's a brief image of how spring boot dispatches between controllers and handles requests, you can consider your dispatcher servlet as the middleware between your front end and your backend (but keep in mind that it is embedded inside the spring boot container)
Angular is an SPA, a single-page-application. It contains everything, Model (changing of business data), View (templates with HTML) and Controller (your click- and other event-handlers in your components).
The Spring backend is an extension of the Model, for performing further data transformation and storing it on a database.
The Model-View-Something (there is also MVVM and derivations) is a pattern that comes from desktop-applications, but it doesn't really fit in the world of SPAs. And the Controller in MVC is often seen as redundant even in desktop-applications (because it just delegates stuff and not taking as big role as View and Model).
Important for you to know when you work with Angular is rather the Component-pattern. It is valid in Angular, in React, Vue and even in Vaadin. A component is chunk of both HTML and script-code manipulating that HTML. And components can nest each other allowing a hierarchical architecture.

CRUD operations using asp.net Icontroller Versus using asp.net ApiController inside my asp.net MVC

If I need to build a web application that implement functionalities related to managing an Medical hospital institution. That application include functionalities to add, update, delete, search and retrieve patients, medical visits, etc.
So I am confused on which approach to follow inside my ASP.NET MVC web application, either to have my controller classes inside my asp.net MVC.
Derived from IController to perform the CRUD operation
OR
Derived from ApiController to perform the CRUD operations
SECOND question is there an approach that is taking over the other, and what are the advantages/disadvantages of each approach over the other?
You can absolutely use both. Nothing stops you to use good old Controller to do CRUD in JSON and MVC is capable of doing it. However, you do not get all the nice features of Web API such as content negotiation, message handlers, media type formatters, etc.
If you do not need any of Web API specific features, then use MVC. But on the long run, Web API will be a better investment as I believe adoption will rocket soon.
If you are going to generate classical HTML pages from your controllers, use the MVC ones. If what you want to return to a client is some kind of serialized data (XML, JSON, ...), use Web API controllers since these make it easier, regarding e.g. content negotiation.
See also Getting started with Web API

Server side MVC +Client side MVC

An application is both JS intensive and has a complex business logic +huge data flow that uses backboneJS to structure JavaScript code and there is a necessity for the server side MVC also (Spring in this case).
Is it a good idea to implement server side MVC (spring ) along with client side MVC (backbone) and are there any compatibility issues between them?
In case both can be implemented.How am i going to coordinate the spring views with the backbone view.
How will client side MVC with template engine collaborate with 'View' of Spring.
Though this question has been asked before, I could not find suitable answer for this. Can somebody help me with a detailed answer?
Backbone.js is primarily used for SPA's (Single Page Applications). Your backbone.js segments ('views') are rendered and re-rendered by data, that is fetched or changed. If your application is going to be javascript intensive, backbone is a great minimal framework that will help organize your application. However, backbone is not so simple when your javascript application becomes quite large. You have to have a thorough understanding of the fundamentals of javascript and have a programming decided pattern. Otherwise you application can become quite a mess even with the use of backbone.js.
Anyhow I digress. Think of you client side application (backbone.js driven) completely separate from your server side application (MVC driven). All your client application needs from your server application is the data. That is why backbone.js is built around a REST API. If you are looking to develop a large javascript application, I would look at using MVC 4's Web API for your REST API, and backbone.js to help organize and standardize your client application.
This article describes how to make an application architecture with both server side MVC and JS MVC , respecting the MVC pattern.
http://blog.javascriptmvc.com/?p=68

Frontend ajax framework work with Grails

I have some knowledge about Flex and Java EE, they are good for web application development. Anyway when I try to write a typical web page that is based on HTML/CSS/Javascript, I think I should take a look at some new program language/framework.
I heard much good news about grails and finally decided to learn it instead of python, ruby, scale… But I still don’t have an overview of the whole structure. Grails is a backend framework like php, jsp, jsf right? So that probably means, it’s a replacement of Java EE in backend, then how about the frontend (need ajax functionality), what are people using with grails?
thanks
Grails is not a replacement, it is an abstraction around the tradition Java EE stack and some extremely popular libraries like Spring and Hibernate, that allows you to go faster by using "convention over configuration".
One component of Grails is GSPs, groovy server pages, which is a front end technology, the V in the MVC (Model View Controller) paradigm. You also have Domain Objects, which are the M (Model), and Controllers, which are the C. Grails also has Services which are best put into the M category (IMHO) of the MVC paradigm. So the Model arrangement in Grails gives you relatively easy persistence (using hibernate under the covers), the Services give you great reusability in your business and transactional logic, and the Controller simply invoke the right logic for a given request, and return the response.
One part of that response is what gets displayed on the screen. In a simple webapp, GSPs fill that role -- the controller tells the browser to render a specific GSP which has data bound to it from the service method that was invoked in the controller. However, it is easy to have the controller return json, so if the endpoint bound to the controller is an ajax request, the client can handle the response itself.
You can use any front end technology you want in a grails app. The default is GSPs, which is an extension of JSPs, which are part of the traditional java stack, but you can use jQuery, Sencha, Sproutcore, Backbone, anything you want. You would have one GSP in that case which bootstraps your javascript code, and the rest would be handled by the client application.
Grails is a web framework and is not just a backend framework. It supports both JSP and GSP ( Groovy Server Pages) for views.
If you plan to use Ajax functionality, you can make use of one of many javascript frameworks available. You can also go ahead with Flex (since you already know it) or use a javascript framework like ExtJs, Dojo, YUI etc...

Spring MVC vs Spring WebFlow

I am doing some research for some social network project which i am going to start. I used Spring before yet i cant make a decision at the moment since there are way too many options to choose.
I would like to use JSF2.0 components on my views , and as far as i figure out webflow is a nice way of doing it yet it is not a must.
What benefits does webflow give over Spring web mvc ? My first impression about WF is it makes things way too complicated.
Thanks in advance
Webflow is about flows in web application.
Think of a Wizzard with several Pages, then Web Flow helps you to connect this Pages (in a flow), and provides a variable scope to connect variable with this flow.
While Spring MVC is "only" about isolated Pages.

Resources