I use Velocity. Implemented a 'Template Service' to expose velocity engine
to pages and components. Using Velocity's datasource resource loader to
load templates from database. Here's an outline:


public interface TemplateService {


 public String getMergedTemplate(String templateName, Map<String, Object>
context);

}


In AppModule

public VelocityEngine buildVelocityEngine(

@Symbol(SystemPreferenceConstants.APACHE_VELOCITY_CONFIG_CATAEGORY) String
preferenceCategory,

@Inject SystemPreferenceService preferenceService,

@Inject SqlSessionFactory sessionFactory, Logger logger) {


 if (velocityEngine == null)

{

velocityEngine = initVelocityEngine(preferenceCategory, preferenceService,
sessionFactory, logger);

}

return velocityEngine;

}


And TemplateServiceImpl.java


@InjectService("VelocityEngine")

 VelocityEngine velocityEngine;

@Override

public String getMergedTemplate(String templateName, Map<String, Object>
context) {

 StringWriter stringWriter = new StringWriter();

 VelocityContext systemProvidedContext = new VelocityContext(context,
systemContext);

systemProvidedContext.put(ipAddressTemplateToken, getRemoteAddress(
requestGlobal.getHTTPServletRequest()));

 if(velocityEngine.resourceExists(templateName))

{

velocityEngine.mergeTemplate(templateName, templateEncoding,
systemProvidedContext, stringWriter);

 }

logger.debug(stringWriter.toString());

return stringWriter.toString();

}


GetRemote address above just takes care of substituting the right host name
etc. in the templates.


Best Regards,
Sanket


On Wed, Jun 11, 2014 at 3:48 PM, Thiago H de Paula Figueiredo <
thiag...@gmail.com> wrote:

> On Wed, 11 Jun 2014 10:20:29 -0300, Boris Horvat <horvat.z.bo...@gmail.com>
> wrote:
>
>  Hi everyone,
>>
>
> Hi!
>
>  I was wondering would it be possible to create a page (i.e. tml and java
>> code) and then sending that data to the database on certain event.
>> basically using tapestry as a template mechanism
>>
>
> Yep! See tapestry-offline or the PageDocumentGenerator service or the
> PartialTemplateRenderer service (5.4+).
>
> --
> Thiago H. de Paula Figueiredo
> Tapestry, Java and Hibernate consultant and developer
> http://machina.com.br
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>
>

Reply via email to