Hi!
> 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

Hopefully you understand that you're moving off the reservation a bit
and that things are going to be harder. If Tapestry was about loading
templates from other locations you can bet that it'd be much easier to
do! :)

> Option 1) Contribute Override
> Option 2) Service decoration

I'd go with option 2...

> 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.

Are you getting an error for your TextBlock component, or is it
rendering correctly? Your logging statements aren't in the code you
shared so it's hard to see where things go awry, but I'll venture a
couple guesses.

1) TextBlock.tml exists in your classpath.

Tapestry never calls the locator.findTemlateResource method if the
template can be found based on the base resource for the
ComponentModel. You can see that in ComponentTemplateSourceImpl at
line 160 (tapestry 5.1.0.5)

2) You are unknowingly excluding component templates in code you haven't shown.

>                                String pageName = 
> getLogicalName(componentModel);
>                                boolean useClassPath = pageName == null;

Are you sure you are getting a good name for your components in your
getLogicalName method? In addition to logging messages you should hook
your code up to a debugger so that you can walk through and see what
happens when it works, or when it doesn't.

Here is a working decorator that I threw together for loading
templates for pages and components from somewhere in the filesystem.

    public PageTemplateLocator decoratePageTemplateLocator(final
PageTemplateLocator locator) {
        return new PageTemplateLocator() {
            public Resource findPageTemplateResource(ComponentModel
model, Locale locale) {
                String base =
"/an/absolute/path/to/somewhere/on/my/local/drive";
                final String className = model.getComponentClassName();
                int i = className.indexOf(".components.");
                File file = null;
                if (i > 0) {
                    String name = className.substring(i + 12);
                    file = new File(base + "/components/" + name + ".tml");
                } else {
                    i = className.indexOf(".pages.");
                    if (i > 0) {
                        String name = className.substring(i + 7);
                        file = new File(base + "/pages/" + name + ".tml");
                    }
                }
                if (file != null && file.exists()) {
                    return new MyFileResource(file);
                } else {
                    return locator.findPageTemplateResource(model, locale);
                }
            }
        };
    }

    private static class MyFileResource extends AbstractResource {
        public MyFileResource(File file) {
            super(file.getAbsolutePath());
        }

        protected Resource newResource(String path) {
            return new MyFileResource(new File(path));
        }

        public URL toURL() {
            try {
                return new URL("file://" + getPath());
            } catch (MalformedURLException e) {
                throw new RuntimeException(e);
            }
        }
    }

Hope that helps,
Josh


On Thu, May 6, 2010 at 7:00 AM, MauricioF <mauricio.fara...@ioko.com> wrote:
>
> 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
>
>



-- 
--
http://www.bodylabgym.com - a private, by appointment only, one-on-one
health and fitness facility.
--
http://www.ectransition.com - Quality Electronic Cigarettes at a
reasonable price!
--
TheDailyTube.com. Sign up and get the best new videos on the internet
delivered fresh to your inbox.

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

Reply via email to