Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails like Views for a Spring MVC Web Application

I am planning a Web Application and I am currently evaluating Frameworks. I have done a lot with Ruby on Rails in the past, but since this app will rely on a lot of code already written in Java and will run on an Application Server infrastructure, it will be in Java, too.

So far I looked at several Frameworks and Spring MVC (3.0) looks the most promising for what I’ve planned. I like how many concepts are similar compared to Rails: front controller, push views and restful URLs.

However, I am still unsure about the view part. I want to be able to have one (or more) application templates that have the basic structure of my website, with logo, footer etc. This template will have some dynamic areas, such as a navigation section etc. (in Rails speek, yield :navigation) Some of the view code, especially forms will be reused; that's why something like partials would be nice, too.

My frontpage might look like this:

+-------------------------------+
| Application.tmlp              |
|                               |
|  +-------------------------+  |
|  | index.tmpl              |  |
|  |                         |  |
|  |  +-------------------+  |  |
|  |  |                   |  |  |
|  |  | login_partial.tmpl|  |  |
|  |  |                   |  |  |
|  |  +-------------------+  |  |
|  |                         |  |
|  +-------------------------+  |
|                               |
+-------------------------------+

So far I found Velocity, Freemarker and Tiles, but I am still unsure which one fits my need best. I like the template concept because I would like some designer to create the templates.

Something that would also be nice but is not as important as the template concept, are automatically created links like the link_to helper from rails:

link_to "Profile", :controller => "profiles", :action => "show", :id => @profile

Which View implementation for Spring MVC comes closest to this? Thanks a lot!

like image 688
phisch Avatar asked Mar 25 '11 09:03

phisch


People also ask

Is spring boot similar to rails?

Rails and Spring Boot can be categorized as "Frameworks (Full Stack)" tools. "Rapid development", "Great gems" and "Great community" are the key factors why developers consider Rails; whereas "Powerful and handy", "Easy setup" and "Java" are the primary reasons why Spring Boot is favored.

Is Spring MVC still used?

@PanadolChong accomodate Spring MVC is still used in some legacy applications, and Spring boot does majority of the configurations under-hood so to have a better understanding of how things work internally, Spring MVC might help.

Does spring use servlets?

So the Spring Web application entry point is, not surprisingly, a servlet. A servlet is, simply put, a core component of any Java web application; it's low-level and does not impose too much in the way of specific programming patterns, such as MVC.

What is backend controller in Spring MVC?

controllers are responsible for receiving the request from the user and calling the back-end services. the figure below shows the flow of requests in the spring mvc framework. when a request is sent to the spring mvc framework the following sequence of events happen. the dispatcherservlet first receives the request.


3 Answers

Have a look on grails it has sitemesh in it, I think this is what you are looking for.

like image 74
moritz Avatar answered Sep 18 '22 13:09

moritz


Couple of useful videos:

  • http://www.parleys.com/#st=5&id=2118&sl=0
  • http://www.parleys.com/#id=1414&sl=1&st=5

Really though, you are spoiled in rails for this sort of stuff, it's going to take more effort with java, everything seams to I am sorry to say (I just started the move from java to rails3).

You might also want to take a look at struts.

like image 35
Ed_ Avatar answered Sep 20 '22 13:09

Ed_


A great framework to build templates for JSPs is Apache Tiles. It can be easily integrated in Spring Web MVC applications.


Alternatively, if you have experience with Ruby on Rails, you could have a look at Spring Roo, adds a "convention over configuration" and code generator layer on top of Spring, similar to what Rails does for Ruby apps.

like image 38
Ralph Avatar answered Sep 19 '22 13:09

Ralph