You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by George Christman <gc...@cardaddy.com> on 2012/11/01 14:41:53 UTC

Configuring Chenillekit-template with tapestry

Hello, I think I've configured chenillekit-template with my tapestry project
as followed. 

<dependency>
            <groupId>org.chenillekit</groupId>
            <artifactId>chenillekit-template</artifactId>
            <version>1.3.3</version>
        </dependency>

public static void contributeVelocityService(MappedConfiguration<String,
Resource> configuration) {
        Resource velocityConfig = new
ClasspathResource("/velocity.properties");
        configuration.add("velocity.configuration", velocityConfig);
    }

However I'm getting the following exception while trying to use it, but
can't seem to figure out if it's something I'm doing with my project or a
chenillekit issue. I'm using tapestry 5.3.6

org.apache.tapestry5.runtime.ComponentEventException
Exception constructing service 'VelocityService': Error invoking method
public static org.chenillekit.template.services.TemplateService
org.chenillekit.template.ChenilleKitTemplateModule.buildVelocityService(org.slf4j.Logger,java.util.Map):
org/apache/velocity/context/Context

context
eventType
    success
location
    classpath:org/healthresearch/eprs/pages/Purchase_Request.tml, line 2

java.lang.RuntimeException
Exception constructing service 'VelocityService': Error invoking method
public static org.chenillekit.template.services.TemplateService
org.chenillekit.template.ChenilleKitTemplateModule.buildVelocityService(org.slf4j.Logger,java.util.Map):
org/apache/velocity/context/Context
org.apache.tapestry5.ioc.internal.OperationException
Error invoking method public static
org.chenillekit.template.services.TemplateService
org.chenillekit.template.ChenilleKitTemplateModule.buildVelocityService(org.slf4j.Logger,java.util.Map):
org/apache/velocity/context/Context

trace

        Triggering event 'action' on Purchase_Request:pr
        Triggering event 'success' on Purchase_Request:pr
        Realizing service VelocityService
        Instantiating service VelocityService implementation via
org.chenillekit.template.ChenilleKitTemplateModule.buildVelocityService(Logger,
Map) (at ChenilleKitTemplateModule.java:46)
        Constructing service implementation via
org.chenillekit.template.ChenilleKitTemplateModule.buildVelocityService(Logger,
Map) (at ChenilleKitTemplateModule.java:46)

java.lang.RuntimeException
Error invoking method public static
org.chenillekit.template.services.TemplateService
org.chenillekit.template.ChenilleKitTemplateModule.buildVelocityService(org.slf4j.Logger,java.util.Map):
org/apache/velocity/context/Context
java.lang.NoClassDefFoundError
org/apache/velocity/context/Context
java.lang.ClassNotFoundException
org.apache.velocity.context.Context

Filter stack frames Stack trace

       
org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
       
org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:244)
       
org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:230)
       
org.mortbay.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:401)
       
org.mortbay.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:363)
       
org.chenillekit.template.ChenilleKitTemplateModule.buildVelocityService(ChenilleKitTemplateModule.java:46)
        java.lang.reflect.Method.invoke(Method.java:597)
       
org.apache.tapestry5.ioc.internal.util.MethodInvoker.invoke(MethodInvoker.java:50)
       
org.apache.tapestry5.ioc.internal.util.LoggingInvokableWrapper.invoke(LoggingInvokableWrapper.java:42)
       
org.apache.tapestry5.ioc.internal.util.ConstructionPlan.createObject(ConstructionPlan.java:60)
       
org.apache.tapestry5.ioc.internal.ServiceBuilderMethodInvoker.createObject(ServiceBuilderMethodInvoker.java:60)
       
org.apache.tapestry5.ioc.internal.OperationTrackingObjectCreator$1.invoke(OperationTrackingObjectCreator.java:45)
       
org.apache.tapestry5.ioc.internal.OperationTrackingObjectCreator.createObject(OperationTrackingObjectCreator.java:49)
       
org.apache.tapestry5.ioc.internal.SingletonServiceLifecycle.createService(SingletonServiceLifecycle.java:29)
       
org.apache.tapestry5.ioc.internal.LifecycleWrappedServiceCreator.createObject(LifecycleWrappedServiceCreator.java:46)
       
org.apache.tapestry5.ioc.internal.AdvisorStackBuilder.createObject(AdvisorStackBuilder.java:63)
       
org.apache.tapestry5.ioc.internal.InterceptorStackBuilder.createObject(InterceptorStackBuilder.java:54)
       
org.apache.tapestry5.ioc.internal.RecursiveServiceCreationCheckWrapper.createObject(RecursiveServiceCreationCheckWrapper.java:60)
       
org.apache.tapestry5.ioc.internal.OperationTrackingObjectCreator$1.invoke(OperationTrackingObjectCreator.java:45)
       
org.apache.tapestry5.ioc.internal.OperationTrackingObjectCreator.createObject(OperationTrackingObjectCreator.java:49)
       
org.apache.tapestry5.ioc.internal.services.JustInTimeObjectCreator.obtainObjectFromCreator(JustInTimeObjectCreator.java:66)
       
org.apache.tapestry5.ioc.internal.services.JustInTimeObjectCreator.createObject(JustInTimeObjectCreator.java:54) 





--
View this message in context: http://tapestry.1045711.n5.nabble.com/Configuring-Chenillekit-template-with-tapestry-tp5717522.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Configuring Chenillekit-template with tapestry

Posted by George Christman <gc...@cardaddy.com>.
I was unable to get Velocity to work, however I switched to FreeMarker and
was able to get things to work with the following configuration. This should
provide an example to anybody else who may encounter issues similar to the
ones I had. 

pom.xml

        <dependency>
            <groupId>org.freemarker</groupId>
            <artifactId>freemarker</artifactId>
            <version>2.3.19</version>
        </dependency>
                
        <dependency>
            <groupId>org.chenillekit</groupId>
            <artifactId>chenillekit-template</artifactId>
            <version>1.3.3</version>
        </dependency>

AppModule

    /*
     * FreeMarker Services
     */
    public static void
contributeFreeMarkerService(MappedConfiguration<String,
freemarker.template.Configuration> configuration) {
        freemarker.template.Configuration fmConfiguration = new
freemarker.template.Configuration();
        fmConfiguration.setWhitespaceStripping(false);
       
fmConfiguration.setClassForTemplateLoading(fmConfiguration.getClass(), "/");
        configuration.add("freemarker.configuration", fmConfiguration);
    }

FreeMarkerServiceImpl

    private final PageRenderLinkSource pageRenderLinkSource;
    
    private final TemplateService templateService;

    public FreeMarkerServiceImpl(@FreeMarker TemplateService
templateService, PageRenderLinkSource pageRenderLinkSource) {
        this.templateService = templateService;
        this.pageRenderLinkSource = pageRenderLinkSource;
    }

    public String emailBodyTemplate(String template, YourObject obj) {
        String pr_url =
this.pageRenderLinkSource.createPageRenderLinkWithContext(YourObject.class,
obj.getId()).toAbsoluteURI();
        
        InputStream input = new ByteArrayInputStream(template.getBytes());
        OutputStream output = new ByteArrayOutputStream();

        Map parameterMap = new HashMap();
        parameterMap.put("obj_number", obj.getobjNumber());
        parameterMap.put("obj_url", obj_url);
        templateService.mergeDataWithStream(input, output, parameterMap);

        return output.toString();
    }





--
View this message in context: http://tapestry.1045711.n5.nabble.com/Configuring-Chenillekit-template-with-tapestry-tp5717522p5717542.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org