I am coming from Struts 1 world. Now I am starting a new project and we are using Spring.
I could use Spring MVC, but seeing how simple it is to use Stripes (no xml is a big plus) I am tempted to use that with our brand spanking new Spring web application. I have no experience in either Stripes or Spring MVC (apart from basic CRUD application).
Question is, what are the downsides of using Stripes as opposed to Spring MVC? Several parts of the application will be RESTful, will it make it harder if we use Stripes? What about validation? I suppose Stripes will be easier to implement, no?
Stripes is a great framework. It's been our framework of choice the past few years and has yet to disappoint.
However, if you mean RESTful in the sense that you want to use HTTP PUT/DELETE, etc. Stripes might not be your answer. I think you'd have to set up Filters, or additional logic in your Beans, it wouldn't be straight-forward (as it seems to be in Spring from a cursory googling).
On the other hand, if you mean things like /app/delete/3 or /app/update/4 & pass POST params, Stripes is an excellent choice.
The Stripes book (Pragmatic Programmers) explains the framework well, and has a chapter on using DI with Spring. All the normal bells and whistles (including validation) are excellent.
Related
I am starting a new pretty big webapp and I am using Spring MVC for complete MVC architecure and I really don't want to change that. On top of that I am looking for a view technology and finally closed with JSF as JSF/facelets is in official EE specification which means they will be the future. Plus prime faces looks promising in acheiving good UI. I know JSF is a MVC framework and I just want to liverage its view part to reduce the development time and at the same time acheiving good and flexible responsive UI
But I went through several posts on StackOverflow itself which prohibits the use of Spring MVC + JSF. E.g, this one
Using JSF as view technology of Spring MVC
This question was answered in 2011 and now new Java EE specification also got released and many changes has happened. Is this point still stands that we should not use JSF+Spring MVC? If it is true, then what are the replacements. One option that looks good for me is Thymeleaf, but only thing that is troubling me is that will it be a good idea to neglect an official specification?
JSF can probably be integrated (I'm not very sure, see the links at the end of my answer) with Spring MVC but it does not look a very good fit to me.
Primarily since JSF is component based, while Spring MVC is action-based. In Spring MVC, the controllers do the processing and can pass the results to anything that renders the view (jsp, html, thymeleaf, apache tiles etc.). Thymeleaf is a good option and I like its approach to templates.
Other alternatives I would suggest to look instead of JSF:
JS frameworks:
I personally prefer this for my projects and there are tons of options to choose like jQuery/jQuery UI, ExtJS etc. for creating you views. You can combine these and make their elements work with fluid frameworks like Bootstrap so that they behave nicely on all screens sizes (not sure how PrimesFaces/RichFaces components behave on all devices)
Frameworks that compile to JS:
Here you have two good frameworks to choose from - Vaadin and GWT. I've used only Vaadin and not GWT so will not comment much on it. Choose this if you don't want to directly fiddle with javascript.
It is not true that only if you use the official Java EE spec you can be in sync with the future. HTML5, JS frameworks etc. are as much the future as JSF is, if not more! Ofcourse JSF of late looks good too (I have not made any production code with it yet, nevertheless have explored it in hobby projects) but you are better off using it on its own with PrimesFaces/RichFaces and not combine it with Spring MVC.
On a middle ground, you can use Facelets instead of Thymeleaf for templating views in Spring MVC. On the other side, you can use JSF with Spring DI, but as I said earlier don't mix JSF and its component libraries with Spring MVC.
Update: Just in case if you absolutely want to try it, here are some links:
http://spring-explored.blogspot.in/2011/11/using-jsf-with-spring-mvc.html
http://papweb.wordpress.com/2011/07/29/spring-mvc-3-jsf-2-with-maven-2-and-tomcat
Areas, in ASP.NET MVC, are handy for breaking a site into smaller, manageable components at a higher level than controllers. They are like mini-MVC pieces within a web application.
Is there an equivalent concept in any Java MVC framework to ASP.NET Areas?
If not, are there any suggestions on best practices when emulating their functionality in a Java MVC framework?
Try Spring MVC. This may be fulfill your wish.
Look at JSP Tiles and Velocity Templates. Tiles should look similiar to Areas.
Take a look on this Web Framework for java: playframework
As such, Java EE does not provide an out of box solution based on MVC but there are many OpenSource projects that have created a solution which implement a MVC framework - try the latest Spring and Struts versions.
I've been looking into JAX-RS lately because I really like the Java platform and a RESTful style of web development. I've read a lot about using JAX-RS for creating RESTful Web Services, but is it possible to use JAX-RS to create RESTful web sites? I guess more specifically, is it possible to use JAX-RS as a controller (to retrieve required data from the server) and then forward control to a view engine to render the appropriate HTML?
I've been googling around but haven't found any resources that show you how to do this.
Thanks for any insight/help.
I think you are having difficulty with your google searches because not many people are doing this. JAX-RS was designed for web services, so developers don't think of using it as a controller for web applications. However, there is no reason it wouldn't work.
Check out this blog post: JAX-RS as the one Java web framework to rule them all?
I think it's exactly the kind of thing you are looking for.
If you truly want to rely just only JAX-RS for your web framework, Jersey might be your best bet. Keep in mind the features you get from it are going to be bare minimum and you are obviously not going to get all the bells and whistles like what's provided by JSF, Wicket, etc.
If you know your web application is going to rely on Spring, perhaps you should consider using Spring MVC 3.0. It provides restful web services-alike and it gives you better features so that you don't need to implement most of them yourself. Granted, Spring MVC 3.0 is not an implementation of JAX-RS and based on what the Spring developer said, it seems like they will never make Spring MVC as an implementation of JAX-RS since they are already quite a few stable implementations out there. However, the syntax is pretty similar in my opinion, or at least I was able to understand them rather quickly even though I have been using Jersey for quite awhile.
dbyrne is right that almost no one is doing this. It's more conventional to use JAX-RS to dump information to JSON or XML. Then you fancy up the web browser with an RIA framework (e.g. Ext JS), which handles manipulating the DOM and injecting data as its fetched in JSON/XML form. This approach is powerful. You can write multiple, possibly non-browser clients for the service, all parsing the same JSON/XML. You can write "one-page" webapps, where all information exchange happens through AJAX after the initial pageload. I urge you to investigate and consider its strengths and weaknesses in the context of your particular problem.
Returning to your question: the answer is "sort of". This functionality is not directly provided by the JAX-RS spec (as of 1.1). However, it is in the JAX-RS reference implementation, Jersey, through the Viewable response object. See this blog post if you want to investigate further: http://blogs.oracle.com/sandoz/entry/mvcj. I want to point out that I have no experience with this side of Jersey. It has been pleasant to write XML/JSON-returning web services with Jersey, but I can't speak to this server-side HTML templating business.
Edit: dbyrne's edited his answer to include a blog post which points to the one mentioned above. I think we've both converged on approximately the same answer.
I want to develop a website with java but I'm absolute beginner in java web development.
I want to use a framework that uses the MVC pattern and Ajax.
I did some search and found that Spring or Struts are suitable but I'm not sure.
could you please recommend a framework?
Play Framework might be a good option because of its incredible simplicity.
I'd recommend Spring:
Developing a Spring Framework MVC application step-by-step
The Stripes Framework is also worth consideration and can be used along with Spring.
http://www.stripesframework.org
It's easy to use and easy to configure. Unlike Struts, which is fairly old hat these days.
There are a plethora of frameworks now and it's worth checking each one that will suit your needs. It's a personal thing and it's good that we're not all restricted to a few.
JRapid is very easy to use. You'll get a working application in minutes and it generates AJAX powered user interface.
I work with Spring Webflow - technology based on Spring MVC. Webflow is described in official help pretty well. Personally, it think Webflow is much more usable than bare Spring MVC, however there are always someone who disagrees.
Moreover Spring (not talking about MVC specifically) can be used outside of web projects, so it seems to me it is advantage of Spring.
Cannot say anything about Struts.
I would recommend GRAILS for fast rapid web application development, that includes scaffolding functionality and web page generation based on data models.
https://grails.org/learn
It is the fastest way for MVC developers.
I have pretty big background of .net, and I've decided that i want to port one of my websites to Java. (now with the asp.net MVC craze, I've figured I'd better learn a more mature approach to MVC).
i've downloaded eclipse (easyeclipse distro to be exact, and am ready and willing to develop my first website in java).
i've programmed j2me application before, so i know the language and some of the framework.
can someone guide me? any advice?
Although I'm not very aware of "asp.net mvc" is all about, I would suggest you to take a look at Spring it may be interesting.
Probably is too complicated at the beginning but when you get the concept it turns out very easy to follow.
Spring has 5 core modules ( which I don't remember exactly ) but they were like:
AOP
ORM
MVC
Core
( some other I'm missing here )
The MVC part uses a lot of annotations to make life easier. There's a very big community around Spring.
Here's an introductory article about spring.
Java has a ton of frameworks you can choose from. The technology stack that I use for my Java development is either:
Spring for IoC.
Hibernate for the data layer.
Struts2 for the MVC framework.
I have also swapped out spring and used Guice for the IoC.
Spring also has MVC, but I tend to like Struts2 better.
I'd recommend looking at Grails, it lets you become comfortable with all the java libraries and frameworks like Spring, SpringMVC, Hibernate, SiteMesh, and so on but gives you a much better DSL for web applications and much more concise code with the Groovy language (think of it as Java with dynamic typing, blocks, closures, and so on).
If you'd rather stick to pure Java I'd recommend looking at the Stripes framework and the following book:
http://pragprog.com/titles/fdstr/stripes
If you interested in web applications specifically, I would recommend using MyEclipse http://www.myeclipseide.com. Basically, this is a version of eclipse with all the web server integration and functionality built in. I've been using it for a few years and it's much easier to develop with than with plain vanilla eclipse. Depending on how much your going to use it, you have to decide whether the $55 annual subscription is worth it for you.
I'm a little confused. does spring framework actually a full blown framework? doesn't Java already have a framework? (by framework i mean all those misc libraries).