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)
Related
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
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 am planning to write a medium scale web application. The server side technologies will include Java, Hibernate, MySQL and the client technologies will include Html, CSS, Javascript and Jquery.
I am looking for the best suitable Java framework for developing web (Struts, Spring, Wicket and so on).
I consider myself heavy Jquery user and I really prefer to do client side stuff.
Wicket for example has modules like the date picker and other modules (AJAX) that should make life easIer with javascript and acts like a replacement to it. But I really prefer javascript.
I thought of writing an application with client side and Java Web Services.
What do you think?
Do you know a framework that isn't afraid of Javascript or don't
suggest replacement to it but tools to use it?
Component-based frameworks generally provide ready-to-use components, that come with their own JavaScript code. If you don't like this, I would stick with action-based MVC frameworks, which generally don't care about what you use at client-side.
My preferences go to Stripes and Spring MVC, but YMMV.
I'd recommend the Play! Framework.
It is a MVC based framework and you can use hibernate, work with a MySQL database and it offers templating for easy HTML generation as well as working well with CSS and Javascript (even includes latest JQuery in download). There are also tons of modules you can add to your project to make development faster and easier.
Play 2.0 should be released fairly soon (currently available in beta) which provides support for CoffeeScript and Less CSS (see here) amongst many other new features.
Edit
StackOverflow answer showing how easy it is to create webservices in Play: https://stackoverflow.com/a/4513047/681807
Well all the framework you have mentioned (struts, spring, wicket) , none of them afraid of javascript.
Like in Struts2 and Spring they have provided build in ajax support for developer like me who is more comfortable with serverside development than client side work (ajax/jquery fancy stuff).
Its on individual how he/she is using JS with any existing framework and you are even free to use simple HTML at you client side with whatever JS way you want to apply to your UI.
Framework support to UI is always intended to provide a close integration to the server-side so as to speedup the overall development time.
In Short i can not recommend any framework as that will dependent upon you project requirements which fits perfectly as per your need, but none of the framework will stop you to use JS in the way you want to use.
I was recently asked in an interview - In java, how do you compare component based frameworks to request based frameworks? I explained EJB as an example of Component based framework and Struts as a request based framework but was not convinced if I did justice to the question.
Any ideas on what interviewer meant and what should have been compared??
regards,
avajurug
They were most likely looking for examples of web frameworks - for example, JSF is a component-based framework, and Struts is a request-based framework.
Request-based frameworks generally make it clear through their APIs that they're working with parsing an HTML request / generating an HTML response, while Component-based frameworks attempt to abstract this away and treat the application as collections of components with renderers and actions to do things.
In my opinion, component-based web frameworks are more trouble than they're worth - their main purpose is usually to make the development of a web app "easier" for developers unfamiliar with web development, and closer to traditional desktop development. However, in practice, when something goes wrong, you need to develop custom components, you need to customize the framework for something that isn't "out of the box" functionality, etc. you need to understand both underlying "traditional" web development and how the component-based framework abstracts it - and if you're an experienced web developer and have existing solutions, utilities, libraries or snippets that worked in "traditional" web development, you'll waste time re-implementing them to work within the component-based framework.
Request based framework is a web framework that gets user's request then determine what the system should do and give back the response back to the user. So the flow is pretty much linear. You're thinking in actions: what does user want (request) -> what user will get back (response). An example of Request based framework is Struts. The modern Grails is pretty much a Request based framework too.
Component based framework is not like that. There is actually no clear sense of the flow from front to back. An example of it is not JSF, because in some way JSF is pretty much quite the same with Struts (since the creator of Struts and JSF is the same). A good example of Component based framework Tapestry and Wicket. The paradigm in these two framework is different. You don't think in actions or request-response, but components and components. You define a component in your application, and you tell what the component does. But the flow does not have to be linear as in Request based framework.
JSF is component based java API, as said Nate, Struts is an action based framework, the Http requests are parsed, while processing the actions in the end the controler Servlet forwards the request to the JSP that will be responsible to generate the response. While in JSF which became a standard for component based web frameworks, there is actually no need to process the requests and the responses as all we need is to write JSP or XHTML pages, bind the components used in the page or the value they should render to properties in backing beans or managed beans and the FacesServlet (controller) does all the job to care about request parsing and redirecting to the JSP that will render the response based on navigation rules specified in faces-config.xml . So as you can see there is a big difference between Struts and JSF as JSF brings a component-event based approach while Struts is more close to the classic JSP/Servlet model. Another thing jpartogi have said the creator of JSF and struts is the same, I just want to mention that Struts is a framwork owned by Apache community while JSF is an API specified by JCP in the JSR-127 for the version 1.1 and JSR-252 for the version 1.2 and has different implementations (SUN-RI, Apache MyFaces...)
Simply, If the framework has objects in java side for each web element so you can change attributes of it or add some functionality, it is component based framework but If framework does not provide objects and you have to put the response value of web element between its tags it is a request based framework.
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