6

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!

phisch
  • 4,571
  • 2
  • 34
  • 52
  • 1
    Did you also consider [Play! framework](http://www.playframework.org) in your evaluation? It is closer to what you try to achieve than any of the solution you currently listed. – gizmo Mar 25 '11 at 10:02
  • I was not aware of the Play! framework. I will take a closer look at it. Thank you! – phisch Mar 25 '11 at 11:17
  • I'm going through the same now... and I haven't found anything remotely close to rails. I decided to use JSF2 (for views) with spring MVC as controllers because I need to support REST services too (which jsf doesn't support). If you find anything interesting, please share it with us! I've just spend the whole morning trying to figure out how to write links as in rails, but I've been defeated, so I need to 'hardcode' the links (except for the base url) – Augusto Apr 04 '11 at 15:36
  • I haven't found anything that fully satisfies my needs. It looks like I will be using Spring MVC with Freemarker. But that means hardcoded URLs... – phisch Apr 05 '11 at 07:54

4 Answers4

6

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

moritz
  • 5,094
  • 1
  • 26
  • 33
  • Definitely look at Grails. Coming from Rails you will feel right at home. You can also use Sitemesh with Spring MVC but unfortunately Spring MVC does not have "reverse URL mapping" (see http://stackoverflow.com/questions/1082759/can-i-find-the-url-for-a-spring-mvc-controller-in-the-view-layer) – sourcedelica Mar 25 '11 at 12:38
2

Couple of useful videos:

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.

Ed_
  • 1,676
  • 2
  • 13
  • 22
2

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.

Pierre Henry
  • 16,658
  • 22
  • 85
  • 105
Ralph
  • 118,862
  • 56
  • 287
  • 383
0

This library does pretty much what you want. It's very similar to rails style templates.

http://code.google.com/p/jst4j/

chubbsondubs
  • 37,646
  • 24
  • 106
  • 138