I'm a newbie in web application development and try to explore some technologies. I have some (very) small experience with Spring-MVC and AngularJS. Recently, I've started to learn Thymeleaf.
Having some really basic knowledge of these technologies, I'm trying to figure out whether and how to use them jointly.
I know there are combinations like REST API as a Spring-MVC controller + AngularJS as a front-end technology that consumes the given data. And that's might be enough for your Single Page Application. But what about applications consisting of many pages which should reuse some components (ex. navbars)? And what about including security mechanisms in those applications?
I've just got to know that there exists Thymeleaf which seems to be a decent template engine. So far I've only used it to create some templates for my HTMLs, but I've heard there are many more appliances - like taking advantage of its nice integration with Spring.
I'm going to create web application consisting of a few pages with security mechanisms (registration, logging etc.), database integration and a lot of user interaction. It would be sort of order system.
Does it make any sense to mix front-end technology like Angular and back-end's Thymeleaf, especially in my case?
I've seen nice post here, but still need some clarification.
I would suggest jhipster. Recently I wrote application with this API and I think its one of the best startup for application with back-end based on SpringMVC and front-end with AngularJS. You can easily generate template from command line which is fully editable
Related
I have a Java EE project using Spring MVC and maybe some JSP files (or plain html not sure yet)
I will use angular.js for the frontend. do I need anything like angular-seed or angular-sproud? OR these frameworks are only for javascript only applications?
AngularJS is a frontend framework, angular-seed and angular-sprout are just examples of how it used, quick start projects.
In your case, the app will most likely use Spring and Java on the backend and have so called one page dynamic JavaScript frontend built in AnglularJS.
Have a look at Rob Harrop's demo project that integrates both technologies, I found it to be really helpful.
Spring MVC REST and AngularJS
I was in the same predicament some time back. The short answer is depends!.. you do not need Angular-Seed to front-end a Java EE app. But you do need some starting point. The problem is that AngularSeed is not really a servlet that can be served up as an SPA.
On the other hand, if you would like to build a front-end completely decoupled from the server then maybe AngularSeed will work for you.
I've written about this here
I began with AngularSeed and was kind of disillusioned. Using a Servlet to serve up the Angular SPA is so much better.
I'm in the "technologies selection" phase of a small, single-page web application that will be heavily-based in AJAX, and which will report to a Java backend.
In a previous question I posted several weeks ago, the SO community at large felt strongly that I would be better off going with a Spring MVC-based web app than with something in JSF. Since Spring is request-oriented, and JSF is component-oriented, it would only make sense to use Spring for something that is going to be getting a lot of asynchronous requests.
If I were going the JSF route, then my next set of decisions would be whether or not to use so-called UI component libraries for the view technology, such as PrimeFaces, IceFaces or MyFaces.
So, I'm wondering: Does Spring MVC have anything similar to, say, PrimeFaces (or its likes) for creating the view component for my page(s)? I know its not component-based, but I'm not all that familiar with Spring MVC's web platform and was wondering what are some de facto standards (if any) or typical technology stacks that Spring web developers use for constructing nice web pages.
And, if Spring just uses run-o-the-mill template engines, would something like Freemarker suffice?
I guess this is a "best practices"-type question for a budding Spring web developer.
Thanks in advance!
Typically, the value so-called UI components lies in how they keep track of user interactions on the server side by integrating with a stateful framework.
Since you have decided to go for a request oriented framework, it would make more sense to use some well-known client-side JavaScript libraries instead. Popular choices include:
Backbone.js – an MVC foundation for user interfaces
jQuery UI for some premade widgets (calendars, etc.)
If you want to go down a more complex route, but with a more desktop-like feel, Sproutcore
Finally, if you wish to avoid JavaScript, you can useGoogle Web Toolkit, which compiles Java to JavaScript and is supposed to have good integration with Spring.
Personally, if I don't need a lot of standard prebuilt widgets, I like Backbone.js + underscore.js + jQuery. I don't like Google Web Toolkit since it feels like writing a pidgin JavaScript, and at that point I prefer to write JavaScript directly.
Yes, JSF is component oriented and Spring MVC is request oriented.
I recommend you to have a look at Thymeleaf Template engine, which is a complete replacement for JSP Engine
....
Thymeleaf Features are:
It allows natural templating.
HTML5 support
Higher performance by utilizing in memory caching
Click here for more
Additionally apart from the things mentioned by Ludovico Fischer, if we consider the same question in now a days tech world than you can use one of the most power full thing of recent world : Angular. There are 2 sample scenario's.
If your architecture is full client side: The integration is very natural for it. Spring MVC expose your service as a REST (JSON / XMl ... ) and your client application with Angular JS consume your JSON. Here the war application (Spring mvc ) must be deployed in a Servlet Container (Tomcat) and your client application can be deployed in the same server or in another server Nginx , Apache etc..
If you want to keep page generation in the server side and only use AngularJS for some nice DOM manipulation so your code must be deployed in the same war (WEB-INF). Mixing the two approachs is not always a good idea. You can try thymeleaf to stay in server side page generation.
Thus in this way you can have simultaneously the cool featuresof angular like templating, testability and clean view code.
Here is another approach (Not JSF) to let Spring MVC to work with ZK UI components - Rich Web Application with Spring MVC CRUD Demo
In that article, it used Spring MVC controller to communicate with ZK UI components. (all in Java code)
I am in the process of beginning development of a web-based user interface and am looking for some expert advice on the right direction for my project.
Since our server-side is to be developed using Java, I am planning to use scriptless-JSP and an MVC framework called FrontMan. FrontMan is a lightweight Java-based MVC framework similar to Struts. I have played around with it and like it. The plan is to use scriptless-JSP assisted by JSTL and JSP tag files. I worked out some prototypes using these technologies and I liked what I had.
Now I am in the process of planning out the client-side stuff. My plan is to use JavaScript, jQuery, jQuery UI to build the front end. During my investigation I came across a very nifty JavaScript MVC framework named JavaScriptMVC. I have to say I really like it. It is not just a client-side MVC framework, but also includes tools for testing, documenting and deploying.
The more I engage in figuring out the client-side plan, I realize that I think this is going to be more of a JavaScript (client-side) app. I am leaning towards doing as much of the work in JavaScript rather than on the backend via Java. The backend will exist mostly for communicating with the database and responding to requests from the client (frontend) for manipulating or retrieving data.
I am rather new to RESTful web services, but in the little I have read about them, I think this might be a good direction to take this project.
I am wondering how I can employ both an MVC framework and REST framework together? Do they make sense together?
I am using Jetty as my web server, so I think that lends itself to using Restlets...?
Anyway, I am not sure how much sense I am making in this post, so I will stop it there for now.
As the previous poster mentioned, it makes perfect sence. MVC let's you separate concerns such that you can keep your application logic separate from your presentational logic.
Your REST controller serves the request you need, populates the model, and exposes it in a REST like manner, typically by returning an xml view to the user. This can be aided by a number of libraries such as xstream, jaxb, castor, xmlbeans, which all provides routines to marshall an object into xml.
Exposing a REST API on the server-side will be a perfect fit for your JS front-end. Your resources will have to expose JSON representations. You will even be able to reuse this web API from other clients such as mobile phones.
As the lead for the Restlet Framework, I can only recommend it for this purpose. Integration with Jetty is very stable :)
Cheers,
Jerome
A quite extensive discussion on this can also be found here:
Separate REST JSON API server and client?
For me it was very helpful.
Yes! It makes sense as Johan Sjöberg said! You can use Spring MVC for example. I like it a lot and think it is very simple and easy to learn. You have an example here.
By the away, for the frontend maybe you would like to check this presentation.
I have been learning ASP.NET MVC in the last few months and I think it is a great improvement over ASP.NET. For me personally, it is a joy to use (as opposed to ASP.NET WebForms :)) I started wondering how the .NET world managed to live so long without any such framework (at least not wide spread and supported by Microsoft as there may be .NET ports of Java MVC frameworks, like Spring.NET).
I know Java folks had such frameworks for a long time and there are many Java MVC frameworks available.
If a web developer was thinking about switching from Java to .NET, which Java framework can be the easiest to switch from, and vice versa, if an ASP.NET MVC developer is thinking about broadening his skillset and learning some Java MVC (web) framework, which would be most similar to ASP.NET MVC architecture- and feature- wise?
Which Java MVC framework is most similar to ASP.NET MVC?
SpringMVC, VRaptor, Grails (Not Java, but somewhat relevant on the Java world)
Play Framework seems to me. It has controllers as classes, actions as methods, Razor-like view engine, object binders and almost everything looks the same.
Even routing seems almost the same.
If I were looking for the simplest framework, I'd dive into Struts. Struts 1.0 was written in a day, and is possibly the most valuable hour-per-hour effort ever spent by a programmer.
If I were looking to broaden my knowledge and/or skills, I might lean towards Spring MVC. If you need some functionality for Java web development, odds are other people wanted it too, and that Spring already has it. (Spring is larger than just Spring MVC; you can simply use Spring MVC, but it integrates nicely with much more, if you choose.)
Wikipedia has a list of a bunch of frameworks here:
http://en.wikipedia.org/wiki/Comparison_of_web_application_frameworks
and of those based on Java technology, about half are component based (that's what you don't want) and the other half MVC. If interested, you could follow the links on some of those to get more information.
In general,
the more mature of them will have more detailed writeups - both in Wikipedia and in the wild. There will also be more documentation, sample code, tutorials,...
The younger ones may be simpler, more fun, more versatile, as they build on the older ones, eliminate known shortcomings and add new features. JSF and Struts, for instance, are "big" in the industry but are considered by many developers (citation needed, I know) to be dated, clumsy, bloated, etc.
You'll probably have trouble getting an answer from people with enough experience to directly compare products on the .Net and Java side; most developers tend to stay on one side of that fence.
While I'm not knowledgeable about similarities with ASP.Net, I submit that Struts and JSF are the workhorses of industry on the Java side, and would be the kind of thing to be useful to have in your CV, even though or perhaps because they're not modern or sexy. Of those two, I think Struts has more of an MVC feel to it.
Apache Struts :
Apache Struts is a free open-source framework for creating Java web applications.
Web applications differ from conventional websites in that web applications can create a dynamic response. Many websites deliver only static pages. A web application can interact with databases and business logic engines to customize a response.
Web applications based on JavaServer Pages sometimes commingle database code, page design code, and control flow code. In practice, we find that unless these concerns are separated, larger applications become difficult to maintain.
One way to separate concerns in a software application is to use a Model-View-Controller (MVC) architecture. The Model represents the business or database code, the View represents the page design code, and the Controller represents the navigational code. The Struts framework is designed to help developers create web applications that utilize a MVC architecture.
The framework provides three key components:
A "request" handler provided by the application developer that is mapped to a standard URI.
A "response" handler that transfers control to another resource which completes the response.
A tag library that helps developers create interactive form-based applications with server pages.
The framework's architecture and tags are buzzword compliant. Struts works well with conventional REST applications and with nouveau technologies like SOAP and AJAX.
I'm coming to Java from C# & ASP.NET MVC, I'd love to find an equivalent in the Java world that I could use on the Google App Engine. I've already started to have a play with FreeMarker and even made the first steps towards writing a very simple framework. Ideally I wouldn't have to do all the hard work though, someone must have done this already! So my question is - what frameworks are there out there that would be familiar for me coming from ASP.NET MVC and I could use them on Google App Engine for Java.
The key things I'd want are:
Simple Routing - /products/view/1 gets mapped to the view action of the products controller with the productid of 1
Template Engine - some way of easily passing 'ViewData' to the view, and from the view easily accessing it, ideally I'd love to avoid anything that is too XMLy (thus why I like FreeMarker).
I am currently working on a Google App Engine app using Spring MVC. It is a lot more mature than ASP.NET MVC so you shouldn't be disappointed. As an added bonus you have the whole IoC power of Spring.
For the view layer I am trying out Velocity. It is pretty simple but I have yet to decide if I will prefer it over JSPs. I had a brief look at FreeMaker but didn't like what I saw. If you want to stay away from XML'y JSP templates than I recommend you give Velocity a spin.
The only problem I have had with Spring on GAE is file uploading. The MultipartResolver implementations both rely on a temporary file directory. After writing my own implementation I'm back to seamless uploading of files in my models.
There are a couple of MVC frameworks that you should consider (that's what I'm doing now). Initially, I went with Spring MVC (3.0) and the cold start on GAE is horrendous! It takes about 10 seconds to start (and I'm not even using anything complex, like spring security, etc), so I need to use a cron job to keep it alive. So I don't recommend that you use Spring at all on GAE.
Take a look at the following frameworks:
VRaptor
Slim3
Google Sitebricks
As for the templating, I use Sitemesh -- used it for quite a while now, so don't see a need to switch.
Hope this helps!
Play Framework would fit the bill. It's a modern MVC framework for Java and has a Google App Engine module to provide compatibility. See http://www.playframework.org/modules/gae.
Another benefit to using Play would be portability. You can deploy Play using its built-in webserver (optionally behind apache for caching, load-balancing, etc) or you can bundle as a .war file for deployment to the many Java application servers (Glassfish, Tomcat, ...).
I also have a strong preference for Freemarker. I suggest that you look at the Induction framework, its template engine is pluggable but the default support is for Freemarker. Induction is a light-weight and fast MVC framework (7.7K lines) but has many features absent in the major MVC frameworks, such as:
dynamic reloading during development when you change the controllers, views or models
file uploads so simple (not much different that a string input)
no configuration required for controllers
capability to analyze dependencies between your Models, Views and Controllers using your IDE
regular expression based URL mappings
best support for managing redirects of any MVC framework
As for the file upload issue raised by #pjesi, Induction allows you to set the size threshold at which files getting written to disk. If this is set large enough it should not try to write any files to disk.
Check out the getting started tutorial here: http://www.inductionframework.org/getting-started-tutorial.html
JavaServer Faces (JSF) I've heard is similar to the microsoft MVC framework. (I use JSF but have never used .NET MVC). And I believe JSF 1.1 works fine on Google App Engine, and I suspect that the newer versions of JSF will work if you stick to using XHTML instead of JSPs as the templates. There are also some nice libraries which let you leverage an AJAX interface on the JSF framework, RichFaces is a popular one.
Check out
JavaServer Faces on sun.com
and also
JBoss RichFaces