17

Is it possible to use Twirl with Spring MVC as the view technology? I would like to use something in place of JSP, and Apache Tiles feels cumbersome to me. Twirl the view technology for the Play Framework looks very cool, and similar to ASP.NET Razor.

https://www.playframework.com/documentation/2.3.x/JavaTemplates

I did a quick Google search but did not uncover much.

greyfox
  • 5,608
  • 15
  • 58
  • 103
  • You may try using JSF 2.x for view technology as shown in several blog entries and q/as here. I haven't worked with Twirl but seems that may fit for what you want/need. – Luiggi Mendoza Jan 12 '15 at 22:24
  • Can you use JSF as a view technology with Spring MVC. I thought you could use Spring + JSF but it didn't make sense or work out well with Spring + Spring MVC + JSF because they are both MVC Frameworks. I may have misunderstood what I've read though so please feel free to correct me – greyfox Jan 14 '15 at 01:30
  • 1
    @greyfox would this help? https://github.com/67726e/Spring-MVC-Twirl – Andrei Sfat Aug 13 '17 at 11:10

1 Answers1

-3

If you are looking for a templating framework to use with Spring MVC I recommend using Spring's Thymeleaf.

This answer also provides some valuable feedback relating to the issue: HTML templates in spring boot similar to play framework

Spring framework does not force you to use any particular view technology. You can use anything that can be integrated. The topic is covered in the documentation (https://docs.spring.io/spring/docs/current/spring-framework-reference/web.html#mvc-view) where you can read about the details on popular choices. However, the most popular is Thymeleaf, which used to be a part of Spring MVC before separation into an independent project. You can find a clear example on how to use it with Spring Boot in the getting started guide.

The templates in Play framework created using Twirl framework are converted into Scala code. You simply pass the data model via template parameter list, just like you do with any method.

In Spring framework you put all date that you want to expose to your view in a so-called model map, which is a simple key-value storage. In the view technology you refer the values using corresponding keys.

mad_fox
  • 2,578
  • 4
  • 24
  • 36