Apache Wicket is a great web framework, its clear separation between logic and markup allows to focus on what's need to be done.
As we use Wicket at SRMvision, we needed to send mails with rather rich templates to our users. The first implementation we used was relying on Wicket to generate these templates using Html. We finally don't use it (our mailing tasks are done by a background job, thus we don't have access to our webapp), but I though the code used in our fast proof of concept could help someone else.

importorg.apache.wicket.markup.MarkupType;importorg.apache.wicket.markup.html.WebMarkupContainer;importorg.apache.wicket.markup.html.basic.Label;importorg.apache.wicket.markup.html.panel.Panel;importorg.apache.wicket.markup.repeater.RepeatingView;importorg.apache.wicket.model.PropertyModel;importorg.apache.wicket.request.Response;importorg.apache.wicket.response.StringResponse;importorg.slf4j.Logger;importorg.slf4j.LoggerFactory;/** * Simple panel allowing to use the templating engine * provided by Wicket to generate HTML. * Typical use would be to generate mail content. * * User of this class will need to subclass it * and create a panel as usual. * Then a call to getHtml() will return the generated Html. * * @author cedric at gatay.fr */publicclassHtmlTemplaterPanelextendsPanel{privatestaticfinalLoggerLOGGER=LoggerFactory.getLogger(HtmlTemplaterPanel.class);/** * Default constructor takes no wicket:id > * the panel will not be added to any component */publicHtmlTemplaterPanel(){super("dummy");}/** * Call this whenever you want to get * the Html for this component * @return Html or empty string */publicStringgetHtml(){finalResponseorigResponse=getRequestCycle().getResponse();try{finalStringResponsestringResponse=newStringResponse();getRequestCycle().setResponse(stringResponse);renderAssociatedMarkup("panel","");returnstringResponse.toString();}catch(Exceptione){LOGGER.error("Unable to build HTML for panel : {}",e.getMessage());}finally{getRequestCycle().setResponse(origResponse);}return"";}@OverrideprotectedbooleangetStatelessHint(){returntrue;}@OverridepublicMarkupTypegetMarkupType(){returnMarkupType.HTML_MARKUP_TYPE;}}

If you want to generate a template using Apache Wicket, you only need to create a Panel and its associated markup which inherits this simple class. Then, when you want to get the Html for your component, call getHtml().
The only drawback of this is that you need a RequestCycle to generate the markup (you'll find out why reading the code).