Tutorial :Which Java HTML templating technology works in a way that is closest to Ruby (erb/haml)?


Among the Java templating solutions such as Apache Velocity, Freemarker, Hamlets, Tapestry, StringTemplate, JSP, JSP Weaver (others?) which would most closely approximate the conciseness and simplicity of similar HTML templating solutions in Ruby - haml/erb. I'm concerned both with the syntax of the templating engine as well as how simply it integrates with Controller code on the server.


i think what u are getting at is this


<% foreach vars do |var| %>    <!-- some html code to do -->    <%=h var %>  <% end %>  


<% for( int i = 0; i < vars.length; i++ ) { %>       <%=vars[i]%>  <% }  %>  

so the tags are similar

for the a java side of the controller , views spring provides a way to separate them nicely


The practice of mixing code and data is frowned upon in Java much more so than in Ruby. The recommended Java practice is to use taglibs instead of code blocks. I mention this only because if you write your Java templates in the same way as typical Ruby templates, other Java developers (I'm assuming you work on a team) are likely to complain.

So now to answer your question.....standard JSPs together with JSTL and EL are really not a bad solution. But for extra conciseness, check out GSPs, the templating solution used by Grails. You can use GSPs in any Java webapp, i.e. you don't need to be using Groovy/Grails.


...You can even use PHP if you want using Quercus. You could then, just like JSP, Velocity, etc. use these as the 'view' and spring or struts, etc. to handle the Controller(s).

A project we did a while ago was with JSP and struts, and spring. They all integrated nicely and we could do what was described.

Most rendering/template engines have varying syntax. The beuty (and beast) of Java is that you can pick which syntax you feel more comfortable with and use that with your controller/container of choice.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »