Underscore.js is a great template engine, simple et efficient, easy to learn.
JSF 2 is one of the most interesting UI framework around, many powerful frameworks have been built on top of it : RichFaces, PrimeFaces, ...
Using both JSF and Underscore is a great opportunity to produce high valuable applications.
But Underscore.js use a default syntax which is not compliant with JSP/JSF compiler.
This syntax is known as ERB style, orignally designed for eRuby.
Here is a sample of this syntax :
JSP/JSF compiler does not taste the "<%" directive since it is a JSP directive or an invalid expression for JSF 2.
Fortunately, you can configure Underscore.js to use another syntax !
Here is new settings for Underscore.js (mustache syntax):
You must put this code in a JS , just before using Underscore.js.
Now, template is updated with new syntax :
Now, you can use Underscore in JSP or JSF 2 pages !
the jee architect cookbook by Olivier SCHMITT est mis à disposition selon les termes de la licence Creative Commons Paternité - Pas d'Utilisation Commerciale - Pas de Modification 3.0 Unported.