Tags: mixer2 java TemplateEngine

Mixer2 is the xhtml dedicated template engine. Because Mixer2 use JAXB (Java Architecture for XML Binding) internally, the usage is not only as a template engine, but also, Mixer2 can be used in another way.

Mixer2 has some different functionality.

  1. as a alternative to JSP, Velocity, and other template engine technology
  2. as a XHTML parser
  3. as as XHTML tag snippet generator

In thie post, I introduce "XHTML snippet generator" functionality of Mixer2.

You must fix up your html template as "full html" like "<html>...</html>" in order to use mixer2Engine.loadHtmlTemplate() .

But if you need to output xhtml tag using mixer2Engine.saveToString(), you can get any tag snippet as string. So, you can create some helper class like custom tag of JSP.

For example, If you must use jsp as the base template but also you want to use Mixer2, You can use them combine them.

If you create the new tag instance, use "new" the tag classes. Also you can use TagCreator.

Div div = TagCreator.div();
	Span span = TagCreator.span();
	span.getContent().add("Hello World !");
	String result = mixer2Engine.saveToString(div);


Hello World !

If you create table tag, you can use TableBuilder.

String[][] data = new String[][]{
    // id, name, price
    {"1", "cookie", "2.50"},
    {"2", "candy",  "3.75"}

TableBuilder tBuilder = new TableBuilder();
for (String[] row : data) {
Table table = tBuilder.build();
String str = mixer2Engine.saveToString(table);



For more detail of TableBuilder, see Mixer2 official site.

How about it ? Mixer2 and other template technology can exist together. Try Mixer2 !