1

Is there a real alternative to JSP tags when using Spring MVC?

I'm using Spring MVC to integrate it to a JS framework. What i'm missing in Spring MVC is a kind of templating framework

I have previously used Facelets templating with JSF2 and I love it.

Is there a framework/technology that integrates well with Spring MVC and offers similar features as Facelets?

  • no (or little) xml configuration
  • can define sections in one template file and fill all supply content for all sections from one file

I was looking at Apache Tiles documentation and it seems that you need to have separate files for each section in template.

Example (pseudocode) :

template.html:

<insert:headerSection>
<insert:bodySection>

using-template.html:

<use-template: template.html>

<define:headerSection>this is a header</define:headerSection>
<define:bodySection>this is a body</define:bodySection>

I know that I can achieve this using JSP but code looks much cleaner and faster to write using Facelets.

If JSP is my best choice I found some suggestions in this thread

Community
  • 1
  • 1
aurban
  • 161
  • 4
  • 16

5 Answers5

1

I think Spring Webflow has JSF 2 support. If you want to stick with pure Spring MVC, it also offers templating with Tiles and Velocity, or you can even write your own custom ViewResolver.

CodeChimp
  • 8,016
  • 5
  • 41
  • 79
  • thanks for the answer but I don't need any of JSF2 features besides Facelets templating and I don't have any complex view flows so I don't need WebFlow. As for Tiles and Velocity I didn't find it as easy to use as facelets (xml config, each piece of code for template must come in a separate file) – aurban Feb 15 '13 at 10:48
  • If Spring doesn't have a Facelets ViewResolver, you could always write your own. – CodeChimp Feb 15 '13 at 19:36
1

After some testing with Tiles I decided to go with JSP. I needs no configuration and I achieved the above functionality writing a simple tag file and using <jsp:attribute/> and <jsp:invoke/> tags.

aurban
  • 161
  • 4
  • 16
1

What about freemarker or velocity, there's a clear explanation about how to integrate those technologies with Spring MVC. Take a look at the following: http://static.springsource.org/spring/docs/3.2.x/spring-framework-reference/html/view.html

gvalenncia
  • 261
  • 3
  • 9
0

It is possible to configure Facelets with Spring MVC. Check it out here: https://github.com/acichon89/springmvcfacelets

Cichy
  • 1,319
  • 3
  • 20
  • 36
0

I consider that frameworks to make templating are getting deprecated. In this regard, you could think about exposing a Restful API, so that you can separate back-end from front-end technologies. This way you can use the benefits of Spring-MVC in back-end and letting the Front-end to decide the technology to build user interfaces (AngularJS).

Spring-MVC supports the build of Restful controllers, you just need to mark your classes as @RestController.

gvalenncia
  • 261
  • 3
  • 9