开发者

Rails like Views for a Spring MVC Web Application

开发者 https://www.devze.com 2023-02-19 12:16 出处:网络
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 wi

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!


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


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.


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.


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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号