Our project is used Tapestry 5.1.0.5, and we unable to upgrade it to lastest
version (5.3) and even 5.2, cause we have lot of legacy code. But it is not
important, just look to PageLoaderImpl (from 5.3 sources):

    public ComponentAssembler getAssembler(String className,
ComponentResourceSelector selector)
    {
        Key key = new Key(className, selector);

        ComponentAssembler result = cache.get(key);

        if (result == null)
        {
            // There's a window here where two threads may create the same
assembler simultaneously;
            // the extra assembler will be discarded.

            result = createAssembler(className, selector);

            cache.put(key, result);
        }

        return result;
    }

    private ComponentAssembler createAssembler(final String className, final
ComponentResourceSelector selector)
    {
        return tracker.invoke("Creating ComponentAssembler for " +
className, new Invokable<ComponentAssembler>()
        {
            public ComponentAssembler invoke()
            {
                Instantiator instantiator =
instantiatorSource.getInstantiator(className);

                ComponentModel componentModel = instantiator.getModel();

                ComponentTemplate template =
templateSource.getTemplate(componentModel, selector);

                ComponentPageElementResources resources =
resourcesSource.get(selector);

                ComponentAssembler assembler = new
ComponentAssemblerImpl(PageLoaderImpl.this, instantiatorSource,
                        componentClassResolver, instantiator, resources,
tracker, request, symbolSource);

                // "Program" the assembler by adding actions to it. The
actions interact with a
                // PageAssembly object (a fresh one for each new page being
created).

                programAssembler(assembler, template);

                return assembler;
            }
        });
    }

Look for cache, for example we have cache-key {ClassName(Template.java),
ComponentResourceSelector(MyImagineSelector.java)}. On app start this cache
is empty and we go to createAssembler method, where real template is created 

ComponentTemplate template = templateSource.getTemplate(componentModel,
selector); //Templates.tml

And after that assembler putted into cache. So we have cached template :(
And how i can change template now? On next pageload with same logical name
and resource selector i hit the cache. I should create new resourceSelector
for each request, and this resourceSelector need access to page logic. I
really think that not easy to use. However i think this approach is much
better than mine, but only since 5.3. 

In 5.2 & 5.1 we have more aggresive cache (by logical name). I try to avoid
this cache by assembling PageImpl manually and render it manually. If you
look to my service you can see that it use methods from PageLoaderImpl to
assembly page (by reflection).

Also you can try to use Dynamic component
http://tapestry.apache.org/5.3/apidocs/org/apache/tapestry5/corelib/components/Dynamic.html.
But it is not worked for me (it throws index out of bounds exception). And
it is in Tapestry 5.3.

--
View this message in context: 
http://tapestry.1045711.n5.nabble.com/Another-approach-to-dynamic-templating-T5-1-0-5-tp4868869p4869388.html
Sent from the Tapestry - User 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