You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by MauricioF <ma...@ioko.com> on 2010/05/05 17:13:10 UTC
How to load tml files from the filesystem instead of classpath?
Hi
I´m evaluating T5 for development of a web application. I´ve been able to
play with it and I think it could be the right tool for the job. There is
only one stopper for this:
The requirement is that the templates must be managed externally by a CMS.
After some investigation it seems that templates MUST live within the war
file or at least be found in the classpath.
The idea is that an editor piblish a template and it´s stored within a
folder in the FileSystem, for example.
So I thought that just implementing a different implementation of
PageTemplateLocator can do the job
but I don´t know where/how to contribute with this new implementation into
the registry of services/modules. Probably I´m talking gibberish as I´m a
newbie in T5 so I can be wrong in the terms,
I hope you get the idea.
I´ve found that PageTempalteLocatorImpl is the one to look at....however
this implementation it´s only invoked from a static methos in InternalModule
public static PageTemplateLocator
buildPageTemplateLocator(@ContextProvider
AssetFactory contextAssetFactory,
ComponentClassResolver componentClassResolver)
{
return new
PageTemplateLocatorImpl(contextAssetFactory.getRootResource(),
componentClassResolver);
}
so this raise the question how is PageTemplateLocatorImpl injected now?
Any ideas to solve the issue, i.e being able to use a external template tml
(componenr or page)
Thanks
Mauricio
--
View this message in context: http://tapestry-users.832.n2.nabble.com/How-to-load-tml-files-from-the-filesystem-instead-of-classpath-tp5009386p5009386.html
Sent from the Tapestry Users 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: How to load tml files from the filesystem instead of classpath?
Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Wed, 05 May 2010 20:43:55 -0300, MauricioF <ma...@ioko.com>
wrote:
> I´ve found a small gotcha with this approach, it works fine for my page
> and components
> However it does not work for render injected blocks.
What do you mean by not working?
Remember that Tapestry is static structure, dynamic behaviour. When you
add a block (new structure) to a template, you need to clear the page
instances from the pool. See PagePoolImp.checkForUpdates() and
UpdateListenerHub.checkForUpdates().
--
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: How to load tml files from the filesystem instead of classpath?
Posted by MauricioF <ma...@ioko.com>.
I´ve found a small gotcha with this approach, it works fine for my page and
components
However it does not work for render injected blocks.
In this template
<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd"
xmlns:p="tapestry:parameter">
EXTERNAL PAGE TEMPLATE
<t:block t:id="video">
<t:playBlock></t:playBlock>
</t:block>
<t:textBlock></t:textBlock>
<t:genericContentBlock block="block"></t:genericContentBlock>
</html>
the page and textBlock work fine getting the tml file from the filesystem.
However genericContentBlock java class has a method to render a block from
the page
@Inject
private RequestPageCache pageCache;
Block getBlock(String blockName) {
Page page = pageCache.get(pageName);
return page.getRootElement().getBlock(blockName);
}
Block beginRender() {
return getBlockBy("video");
}
It seems the rendering of that Block is not affected by this decorator :(
I´ve added traces and I can not see anything related to video, but I can see
traces for the other components...
Thanks!
--
View this message in context: http://tapestry-users.832.n2.nabble.com/How-to-load-tml-files-from-the-filesystem-instead-of-classpath-tp5009386p5011689.html
Sent from the Tapestry Users 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: How to load tml files from the filesystem instead of classpath?
Posted by MauricioF <ma...@ioko.com>.
I managed to override the class but later I realize that I did not want to
have this behaviour for all the T5 standard components :(
So using a decorator fits better because I can reuse the original approach
in the case I don´t find the template in the fileSystem.
This is a first version of the code in case is useful for someone. Please
nothe that this uses a very basic approach to build the name of the file. A
file resource is built using URIResource (thanks to the chillenkit project)
which admits several constructors and one of them is File
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) {
System.out.println("Searching in classpath");
resource = original.findPageTemplateResource(
componentModel, locale);
} else {
String path = format("%s.%s", pageName,
InternalConstants.TEMPLATE_EXTENSION);
System.out.println("Reading file: " + "C:\\temp\\" + path);
if (path != null) {
File file = new File("C:\\temp\\" + path);
try {
resource = new URIResource(file);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
System.out.println("Error file not found!!!!");
resource = original.findPageTemplateResource(
componentModel, locale);
}
}
}
return resource;
}
};
}
I,m able to load external pages and having some issues with component
templates. But I´ll find out how to fix it.
Thanks everybody fot your support. I think now I´ve become a new T5 user and
I like what I see ;)
--
View this message in context: http://tapestry-users.832.n2.nabble.com/How-to-load-tml-files-from-the-filesystem-instead-of-classpath-tp5009386p5011570.html
Sent from the Tapestry Users 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: How to load tml files from the filesystem instead of classpath?
Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Wed, 05 May 2010 19:11:51 -0300, MauricioF <ma...@ioko.com>
wrote:
> Caused by: org.apache.tapestry5.ioc.internal.OperationException: Service
> interface org.apache.tapestry5.internal.services.PageTemplateLocator is
> matched by 2 services: PageTemplateLocator, PageTemplateLocatorFileBased.
Try not adding PageTemplateLocatorFileBased is a service to avoid that
problem. Inject ObjectLocator and use its autobuild() method to create and
instance of your object.
> An alternative can be decorate the service (ignoring whatever it does
> and my small bits of logic
> to return a resouce based in the FileSystem) but I´d rather do it using
> overriding.
Decorating would have the advantage of loading from the file system just
the templates you need, leaving the other ones (such as the templates of
components provided by Tapestry) being loaded normally.
--
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: How to load tml files from the filesystem instead of classpath?
Posted by MauricioF <ma...@ioko.com>.
Thanks Martin, testing that approach right now..
--
View this message in context: http://tapestry-users.832.n2.nabble.com/How-to-load-tml-files-from-the-filesystem-instead-of-classpath-tp5009386p5011538.html
Sent from the Tapestry Users 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: How to load tml files from the filesystem instead of classpath?
Posted by Martin Strand <do...@gmail.com>.
Decorating will probably work, but you can also construct the service from within your contributing method:
public static void contributeServiceOverride(MappedConfiguration<Class, Object> configuration, @ContextProvider AssetFactory contextAssetFactory, ComponentClassResolver componentClassResolver)
{
configuration.add(PageTemplateLocator.class, new PageTemplateLocatorFileSystemImpl(contextAssetFactory.getRootResource(), componentClassResolver));
}
On Thu, 06 May 2010 00:11:51 +0200, MauricioF <ma...@ioko.com> wrote:
>
> Mmmmm, overriding makes T5 throw an exception
>
> Caused by: org.apache.tapestry5.ioc.internal.OperationException: Service
> interface org.apache.tapestry5.internal.services.PageTemplateLocator is
> matched by 2 services: PageTemplateLocator, PageTemplateLocatorFileBased.
> Automatic dependency resolution requires that exactly one service implement
> the interface.
>
> What I´ve done:
> In my module
>
> @ServiceId("TemplateFileSystem")
> public static PageTemplateLocator
> buildPageTemplateLocatorFileBased(@ContextProvider
> AssetFactory contextAssetFactory,
>
> ComponentClassResolver componentClassResolver)
> {
> return new
> PageTemplateLocatorFileSystemImpl(contextAssetFactory.getRootResource(),
> componentClassResolver);
> }
>
> public ComponentTemplateSource
> buildComponentTemplateSource(TemplateParser parser,
> @InjectService("TemplateFileSystem") PageTemplateLocator locator,
> ClasspathURLConverter classpathURLConverter)
> {
> ComponentTemplateSourceImpl service = new
> ComponentTemplateSourceImpl(parser, locator, classpathURLConverter);
> return service;
> }
>
>
> As you can see it doe not matter if I add the serviceId and then inject the
> service by name!
> The problem is that the one which is throwing the exception is in
> org.apache.tapestry5.internal.services.InternalModule (which I cannot
> modify)
>
> So in this case I cannot override?
>
> An alternative can be decorate the service (ignoring whatever it does and my
> small bits of logic
> to return a resouce based in the FileSystem) but I´d rather do it using
> overriding.
>
> Thanks!
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: How to load tml files from the filesystem instead of classpath?
Posted by MauricioF <ma...@ioko.com>.
Mmmmm, overriding makes T5 throw an exception
Caused by: org.apache.tapestry5.ioc.internal.OperationException: Service
interface org.apache.tapestry5.internal.services.PageTemplateLocator is
matched by 2 services: PageTemplateLocator, PageTemplateLocatorFileBased.
Automatic dependency resolution requires that exactly one service implement
the interface.
What I´ve done:
In my module
@ServiceId("TemplateFileSystem")
public static PageTemplateLocator
buildPageTemplateLocatorFileBased(@ContextProvider
AssetFactory contextAssetFactory,
ComponentClassResolver componentClassResolver)
{
return new
PageTemplateLocatorFileSystemImpl(contextAssetFactory.getRootResource(),
componentClassResolver);
}
public ComponentTemplateSource
buildComponentTemplateSource(TemplateParser parser,
@InjectService("TemplateFileSystem") PageTemplateLocator locator,
ClasspathURLConverter classpathURLConverter)
{
ComponentTemplateSourceImpl service = new
ComponentTemplateSourceImpl(parser, locator, classpathURLConverter);
return service;
}
As you can see it doe not matter if I add the serviceId and then inject the
service by name!
The problem is that the one which is throwing the exception is in
org.apache.tapestry5.internal.services.InternalModule (which I cannot
modify)
So in this case I cannot override?
An alternative can be decorate the service (ignoring whatever it does and my
small bits of logic
to return a resouce based in the FileSystem) but I´d rather do it using
overriding.
Thanks!
--
View this message in context: http://tapestry-users.832.n2.nabble.com/How-to-load-tml-files-from-the-filesystem-instead-of-classpath-tp5009386p5011392.html
Sent from the Tapestry Users 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: How to load tml files from the filesystem instead of classpath?
Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Wed, 05 May 2010 17:50:00 -0300, MauricioF <ma...@ioko.com>
wrote:
> Other issue I´ll have to face is about caching templates, because I´d
> like T5 to detect when a template has changed to remove it from the
> cache)
I guess you'll need to do this yourself.
> Ideally I´d like to register in my module a new implementation of
> PageTemplateLocator
You're looking for module autoloading and Tapestry-IoC already implements
that: http://tapestry.apache.org/tapestry5.1/tapestry-ioc/autoload.html.
> Any other idea how can I do this? (If you think override
> PageTemplateLocator is not the right thing..)
Overriding or decorating PageTemplateLocator through Tapestry-IoC is the
right thing AFAIK. :)
--
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: How to load tml files from the filesystem instead of classpath?
Posted by Martin Strand <do...@gmail.com>.
On Wed, 05 May 2010 22:50:00 +0200, MauricioF <ma...@ioko.com> wrote:
> Ideally I´d like to register in my module a new implementation of PageTemplateLocator
> Any other idea how can I do this? (If you think override PageTemplateLocator
> is not the right thing..)
>
> Thanks
Yes, that's what you need to do. You can override built-in services by adding a contribution to ServiceOverride:
http://tapestry.apache.org/tapestry5.1/tapestry-ioc/cookbook/override.html
In your case I believe it would look something like this:
public static void contributeServiceOverride(MappedConfiguration<Class, Object> configuration)
{
configuration.add(PageTemplateLocator.class, new MyOwnImplementation(...));
}
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: How to load tml files from the filesystem instead of classpath?
Posted by MauricioF <ma...@ioko.com>.
Hi Thiago, thanks for your reply!
Totally agree with your statement: Tapestry templates are meant to be used
by developers, not users.
But in our CMS there are some sections which will require some technical
knowledge.
The good thing of templates is that they are easy to understand by a web
developer
as it´s a mix of html and some components.
For example we want to be able to publish any web static file (css,
images,etc) and templates.
For the first one I´ve already used some tricks creating a contribution to
the assetFactory and assetAliasMAnager so now I can do things like
@Inject
@Path("uri:http://www.someurl.org/myfile.jpg")
private Asset testAsset1;
@Inject
@Path("uri:file:///C/templ/myfil.png")
About your question:
> What parts of the page need templating?
Everything. The idea is that we use the cms as a way of defining the page as
layout made of different blocks in the cms. So you can see our POJO objects
in the cms are Page, Block (and loads of subtypes)
Each block will have a template (.tml). So we want to be able to modify the
template just publishing from a CMS. Probably the CMS could be in other
machine, so probably using shame shared NFS would do.
Other issue I´ll have to face is about caching templates, because I´d like
T5 to detect when a template has changed to remove it from the cache)
As you can see we do really need an external template loading mechanism.
Ideally I´d like to register in my module a new implementation of
PageTemplateLocator
Any other idea how can I do this? (If you think override PageTemplateLocator
is not the right thing..)
Thanks
--
View this message in context: http://tapestry-users.832.n2.nabble.com/How-to-load-tml-files-from-the-filesystem-instead-of-classpath-tp5009386p5011085.html
Sent from the Tapestry Users 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: How to load tml files from the filesystem instead of classpath?
Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Wed, 05 May 2010 12:13:10 -0300, MauricioF <ma...@ioko.com>
wrote:
> Hi
Hi!
> I´m evaluating T5 for development of a web application. I´ve been able to
> play with it and I think it could be the right tool for the job. There
> is only one stopper for this:
> The requirement is that the templates must be managed externally by a
> CMS.
Tapestry templates are meant to be used by developers, not users. There
were some discussions about this in this list already, one of them can be
read here:
http://old.nabble.com/Tapestry-Templates-%2B-Scripting-Language-(CMS)-to27191065s302.html#a27191192.
What parts of the page need templating?
> so this raise the question how is PageTemplateLocatorImpl injected now?
Through Tapestry-IoC
(http://tapestry.apache.org/tapestry5.1/tapestry-ioc/). You can override
(http://tapestry.apache.org/tapestry5/tapestry-ioc/cookbook/override.html),
advise (http://tapestry.apache.org/tapestry5.1/tapestry-ioc/advice.html)
and decorate
(http://tapestry.apache.org/tapestry5.1/tapestry-ioc/decorator.html)
services using Tapestry-IoC.
--
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: How to load tml files from the filesystem instead of classpath?
Posted by Inge Solvoll <in...@gmail.com>.
I'll do the conclusion:
Isn't it nice that we have a framework that actually allows us to freely
override such a crucial feature in a radically different way than it was
originally intended? The override is very logical and it just works.
This is the number one reason for me to use T5 :)
Thanks to Mauricio for providing a very nice example to the mailing list!
Regards
Inge
On Mon, May 10, 2010 at 9:02 AM, MauricioF <ma...@ioko.com>wrote:
>
> Thanks Josh for your reply.
>
> After looking the code the reason was 1) TextBlock.tml existed in my
> classpath.
> so my implementation of PageTemplateLocator was never triggered as you
> mentioned.
>
> Now everything works like a charmm!
>
> Thanks everybody
> Mauricio Farache
> --
> View this message in context:
> http://tapestry-users.832.n2.nabble.com/How-to-load-tml-files-from-the-filesystem-instead-of-classpath-tp5009386p5029201.html
> Sent from the Tapestry Users 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: How to load tml files from the filesystem instead of classpath?
Posted by MauricioF <ma...@ioko.com>.
Thanks Josh for your reply.
After looking the code the reason was 1) TextBlock.tml existed in my
classpath.
so my implementation of PageTemplateLocator was never triggered as you
mentioned.
Now everything works like a charmm!
Thanks everybody
Mauricio Farache
--
View this message in context: http://tapestry-users.832.n2.nabble.com/How-to-load-tml-files-from-the-filesystem-instead-of-classpath-tp5009386p5029201.html
Sent from the Tapestry Users 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: How to load tml files from the filesystem instead of classpath?
Posted by Josh Canfield <jo...@gmail.com>.
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 <ma...@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-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@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-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: How to load tml files from the filesystem instead of classpath?
Posted by MauricioF <ma...@ioko.com>.
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-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: How to load tml files from the filesystem instead of classpath?
Posted by Nicolas Bouillon <ni...@bouil.org>.
Le 05/05/2010 17:13, MauricioF a écrit :
> Hi
>
> I´m evaluating T5 for development of a web application. I´ve been able to
> play with it and I think it could be the right tool for the job. There is
> only one stopper for this:
> The requirement is that the templates must be managed externally by a CMS.
>
I had the same kind of requirement, but for the ".properties" files
containing the translations.
In fact the .properties we wrote are imported into a database,
translated by outsourced translator, and then exported to, for example,
Index_fr.properties, Index_de.properties, etc...
To be able to update the translations files in production without
redeploying the WAR, i've just added a prepend classpath to my web
application, pointing to the file system containing the ".properties"
files, with the same directory structure than my application. Then I
just have to do "svn up" in that directory to update my translations.
I guess it could work also for template files.
Nicolas.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org