Hi 

I´m a bit stuck with this.. 

I´ve spent nearly all the day with this and I don´t get what I want what´s
really annoying…so my love relation with T5 is turning into frustration
right now 
Still trying to see how I can implement external loading of templates….

Option 1) Contribute Override
Option 2) Service decoration


Contribute Override

        public static PageTemplateLocator       
buildPageTemplateLocatorFileSystem(
                        @ContextProvider AssetFactory contextAssetFactory,
                        ComponentClassResolver componentClassResolver) { 
                 return new 
PageTemplateLocatorFileSystemImpl(contextAssetFactory.getRootResource(), 
componentClassResolver);
        }

        public static void contributeServiceOverride(MappedConfiguration<Class,
Object> configuration, 
                                             @ContextProvider AssetFactory 
contextAssetFactory, 
                                                              
ComponentClassResolver
componentClassResolver, 
                                                       @Local 
PageTemplateLocator
templateFileSystem)
        {
                configuration.add(PageTemplateLocator.class, 
templateFileSystem);
        }


I,m getting an exception

main  ERROR Registry: Construction  of service  'ServiceOverride' has failed
due to recursion: the service depends on  
itself in some way. Please check 
org.apache.tapestry5.ioc.internal.services.ServiceOverrideImpl(Map)  (at
ServiceOverrideImpl.java:31) via  
org.apache.tapestry5.ioc.services.TapestryIOCModule.bind(ServiceBinder)  (at
TapestryIOCModule.java:46) for references to another service that is itself
dependent on service 'ServiceOverride'. 

In this threaD Howard M. Lewis  give us some pointer
http://old.nabble.com/ServiceOverride-recursion-issue---T5.2-td28117909.html

He´s suggestingh using local and that´s what I´ve done with no success.


Option 2) 
USING A DECORATOR

public PageTemplateLocator decoratePageTemplateLocator( final
PageTemplateLocator original) {

                return new PageTemplateLocator() {
                        public Resource findPageTemplateResource( 
ComponentModel componentModel,
Locale locale) {

                                String pageName = 
getLogicalName(componentModel);
                                boolean useClassPath = pageName == null;
                                Resource resource = null;

                                if (useClassPath) {
                                        resource = 
original.findPageTemplateResource( componentModel, locale);

                                } else {

                                        String path = format("%s.%s", pageName,
InternalConstants.TEMPLATE_EXTENSION);
                                        
                                        if (path != null) {
                                                File file = new 
File("C:\\temp\\" + path);
                                                
                                                try {
                                                        resource = new 
URIResource(file);
                                                        useClassPath = 
(resource.toURL() == null);
                                                        
                                                } catch (MalformedURLException 
e) {
                                                        
                                                        useClassPath = true;
                                                        
                                                }
                                                                                
                
                                                if (useClassPath) {
                                                        resource = 
original.findPageTemplateResource(componentModel, locale);
                                                }
                                                        

                                        }

                                }

                                return resource;
                        }
                };
        }

This seems to work partially ok.
I´ve a decorator with some debug logging statements.

This sample case

page template (page.tml)


<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd";
      xmlns:p="tapestry:parameter">

EXTERNAL PAGE TEMPLATE      

<t:textBlock></t:textBlock>

 </html>



I can see that my decorator is triggered when rendering the pate template
(and I can see it loads page.tml from the filesystem, which is ok)
However I cannot see  any debug statement to render the textBlock!!!

So not sure why the decorator is not invoked when rendering a component
template.
  
A bit more investigation shows me that in the T5 InternalModule

    public ComponentTemplateSource
buildComponentTemplateSource(TemplateParser parser, PageTemplateLocator
locator,
            ClasspathURLConverter classpathURLConverter)
    {
        ComponentTemplateSourceImpl service = new
ComponentTemplateSourceImpl(parser, locator, classpathURLConverter);

        updateListenerHub.addUpdateListener(service);

        return service;
    }

ComponentTemplateSourceImpl is the one responsible , just wondering if by
some reason decoration does not work around this builder method, which would
explain this issue.
-- 
View this message in context: 
http://tapestry-users.832.n2.nabble.com/How-to-load-tml-files-from-the-filesystem-instead-of-classpath-tp5009386p5014311.html
Sent from the Tapestry Users mailing list archive at Nabble.com.

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

Reply via email to