Design decision between backbone.js or Spring MVC - spring-mvc

I have to develop an application which takes XML reports stored in File System parse it and put it into database and display the reports by querying the database in various MIME types(XML,JSON,RSS and HTML). So what I have done till now is parsed the XML reports in the file system ,setup schema for database in MongoDB,put data in database using Spring-data and also managed to have a web service which shows rough draft of reports in XML,JSON and RSS feed.Now I want to display the reports in HTML as well and my supervisor suggested me to use Backbone.js to dispaly it in HTML format by calling the web service.Kindly advice me to choose b/w Backbone.js or write another Spring MVC web service which generates reports in HTML.
Thanks in advance
Swaraj

What you are asking are two different things and choosing between them.
You have to know what your overall objective is with the webapp is and what framework is best for it.
Short answer, Spring MVC integrates with Dojo.js right out of the box, which might do what you need to do, but since your supervisor is suggesting otherwise your options are:
Use Spring MVC to construct and display the data in the HTML using what ever render of your choice.
Or
Build out your Spring MVC wepapp API so that you can use a JavaScript MVC framework, such as Backbone.js or one of the many others (see TODOMVC for samples), to interact with your spring controllers.
Option 1 might be easy enough, used in conjunction with JavaScript or jQuery and plugins
Option 2 would be good if your webapp is complex and will be mostly a SPA (single page app) that utilizes a lot of JavaScript and you want a way to organize your js code better. See JavaScript MVC diagram for an example of how it works.

Related

ASP.NET web api with angular project structure

First time asp.net webAPI + angular project. From many examples I've seen online I've found there are basically two ways for handling the views.
The first (which I have seen in many tutorials and courses) - use APIcontrollers only, so that the view are generated by angular. That means my project structure would have a folder 'app' and it will contain the html files (probably inside a 'view' folder). The routing will be done using angular routes. I will only have APIControllers in the project (without the regular Controller object).
Example project: https://github.com/DanWahlin/CustomerManagerStandard
The second - using Controllers to generate the views, using Razor (cshtml files), and angular incorporated into those (i.e ng-click inside the cshtml). There's no special 'app' folder for angular etc.
example project : https://github.com/Wintellect/Angular-MVC-Cookbook/tree/master/CRUDOperations
So, I'm wondering what are the pros and cons for each method, and when shall I use which one. Examples projects would be great as well.
I can only assume that the first method is more modular and differentiate server and client. However, using it means I'm loosing razor (Do I even need it?)
Thanks!
I actually had to make this decision a few months back myself.
This comes down to what you feel is more comfortable. I chose to do angular and WebAPI controls only. It makes me think in terms of true separation of concerns just easier, angular is your presentation layer and webapi is your services. This also gives you the freedom to do the compression/formatting of the actual html pages(instead of the cshtml pages which you really have no control over).
One more pro for WebAPI only is scalability, you would really only need one webserver for the webpages but you can scale out your WebAPI, this will allow you WebAPI to be your api as well as your clients as well.
Razor is just a view engine and in my experience angular does a good job of templating and directives to bear the cost of losing razor. You'll probably end up writing pure HTML in your razor files anyways once you get a hang of directives which means you'll have more of an issue adding a new view. Who wants to create a new controller, new action and a new view, and then have to do that in angular. It just ends up being easier and less complex to let server serve the html files, and let angular do all your routing and logic for you.
I believe too that the html files get cached too so you will see less round trips as you navigate page to page in angular.
As a person who works at a Microsoft shop and loves AngularJS for nearly all my front-end, the sooner you get away from mixing Razor and AngularJS, the better, especially if you are going for a SPA.
The only time I would recommend using Razor at all would be to generate the landing page (and possibly login page/admin area). It does give a nice way to provide authentication to access the app and then use Web Api Authorization attributes to do the rest of the authentication.

Concept explanation SPA (Single Page Application)

I am working on an web application/site and I want to do it with AngularJS, ASP.NET and Typescript.
I read about the Single Page Application concept, but I still have some question about this whole concept:
Why should I prefer a SPA (Single Page Application) before multiple pages.
I also have some questions about integrating it with ASP.NET:
In ASP.NET it standard generate a nice bootstrap layout with about 3 pages at the top. So I think that it means that I need to combine all these pages to one page. But how can I get it to work together with the routing of ASP.NET. Because you will use the routing of AngularJS, and I want to keep the login from ASP.NET (Can you maybe give an example so I can see how it works).
If I got it correctly Typescript in this concept will replace the JSON webservice. Is this correct or do I got this all wrong?
If you could answer one of my questions I would be very thankful.
SPA's are a trend, they are mostly useful to move the load on your server to the clients. Only data requests will be made to the server, rendering is done on the client machine.
There are still other benefits, but I guess this is the most relevant.
As to your questions regarding integration into ASP.NET.
Building an SPA does not mean all has to fit in one page. Look at AngularJS, it will fetch views as separate requests (see templateUrl in routingprovider). That being said, you can use ASP.NET MVC and serve ASP.NET Views as Angular Templates. This allows for a neat separation of Model, View and Controller parts.
Typescript is Microsoft's JavaScript dialect. It will not replace JSON and you will probably want to use JSON to exchange data with your server. You could use XML, but that is a little bit oldfashioned (and way more bulky).
I have no experience with TypeScript so I would not consider doing that (coffee might be a better alternative), but there are also some quicks in JavaScript you need to be aware of. I would suggest to search Douglas Crockford and Javascript on Youtube. The guy has great talks that can make you a JavaScript pro.

What is (a relative) better strategy to load a resource file as a template in Spring 3.x mvc?

I am learning Spring 3.x MVC. I now have a regular web page setup with built in css in the html.
My first question - where should I store external css files and link them with the html files and still keep the L18n option available in the future? Should I keep the css in the WEB-INF/resources/css and make the resource directly available? But would it eliminate the L18n option?
My second question - to query a database, I have a query template XML file. I need to load the template into my model and modify a few keywords and send it through the database api. First thing that came to my mind is to put the keywords into something like ${keywords} in the template (like how the views are resolved), but I am not sure where to store the XML file (in the classpath? or in the web-inf?)? and how to set the variable in the template XML from my model?
Thanks,
Jason
It seem like you have two separate questions here.
In regards to CSS location, I'd recommend to try out Spring Roo tool. You can quickly generate a working web application with l18n support and number of other advanced features. This application could serve as a foundation for your own app or you can study its structure to learn many good practices for building Spring web applications.
In regards to your second question it is unclear what you want to substitute and at what time (i.e. deployment time or runtime) and also unclear what SQL templates you are using. I'd recommend to use iBatis/MyBatis framework, which has great integration with Spring and advanced templating support. There you can load your Spring contexts and template xmls from the Java application classpath.

Creating web forms in runtime

This is a question of a more general nature. I'm building a system that can create dynamically forms and reports during runtime. For that purpose we're using data dictionary for storing data and XML definitions as blueprints for creating forms and reports as needed. We're using WWF Rule Engine for necessary business logic.
Right now I'm evaluating what would be the best approach to upgrade my system to allow creating web applications from my XML definition. I'm thinking of creating master page that would have a menu of defined forms and clicking on them would render them to the user.
Web forms are different beast than win forms. What is the best approach for this?
I'd go here with ASP.NET MVC if possible - you could create the form on client side for better performance (for example using jQuery).
On the other side - you can create the forms in the View and send it to the user according to the blueprint. It's plain HTML creation.
Anyhow, if you're using ASP.NET Web forms you can iterate through the XML, interpret it and add then add to the form. It would be more complicated I think.

what are options availble for rich reports implementation in asp.net mvc?

I want to implement rich reporting features in one of our asp.net mvc based web applications. The required features in the reports are
Graphs
Charts
Grouping, sub totals, page breaking, etc
Ability to export to excel, pdf, csv and other formats
Printing Support
We are ready to purchase commercial controls(if free ones are not available). Please suggest us the best of available options.
I do not know what rich reporting packages are out there that are 100% ASP.NET MVC-driven. I've seen a few talk about MVC.
But technically, you don't need an MVC-version of reporting controls. ASP.NET MVC allows you to use standard ASP.NET functions, such as WebForms, postbacks, server controls, etc. This is easy as a drop-in-place solution because ASP.NET MVC's default Convention-over-Configuration programming checks to see if a directory or file exists first, before being routed through the controller logic.
So, if there are no Asp.Net Mvc versions of graphs and charts you like - then fear not, you can fall back to the ones you've used for your previous asp.net forms projects. Even though I recommend sticking it into a dedicated directory (i.e. /reports) to keep a clean website.
I suggest you try and use a regular web form for the reports, with graphic, charts, and any other ontrol you might need. MVC views and web forms can live in the same project, noting wrong with that. At least until you find a way to do it using a MVC view.
In my own opinion, you don't have to do everything MVC in a project, you are "allowed" to do whatever you need to do to make your application work the way you want to.
You can use the asp.net chart control which is free to download and supported with ASP.net MVC
I found this while searching for something similar.
http://www.componentsource.com/products/syncfusion-essential-studio-aspnet-mvc/index-gbp.html
I haven't used it though. There is a trial download.

Resources