I'm doing it and it works. I create components from a class that
specificates how to create a template dinamically, so it creates the
template on the fly.
Here is a simplified version of  my "findTemplate" method of ITemplateDelegate:

    public ComponentTemplate findTemplate(IRequestCycle cycle,
            IComponent component, Locale locale) {

        //I ask here if it's a page of my magic class
        if (component instanceof TemplatelessPage) {

  

            TemplatelessPage page = (TemplatelessPage) component;

            //I told the page to create a template
           char[] templateChars;
           templateChars = page.createTemplate();

            //I create a parser for the template
            TemplateParser parser = new TemplateParser();
            ITemplateParserDelegate delegate = new TemplateParserDelegateImpl(
                    component, cycle);

            //I parse the template
            TemplateToken[] tokens;
            try {
                tokens = parser.parse(templateChars, delegate, null);
            } catch (TemplateParseException e) {
                throw new RuntimeException(e);
            }

            ComponentTemplate template = new ComponentTemplate(templateChars,
                    tokens);

            return template;

        } else {
            return null;
        }
    }

This was a simplified version.
I've added diferent layouts to a Page, so the same specification can
render in diferent ways.
I've also added cache features, so you don't need to create a template
every time for different instances of the same page.

Tell me if it was usefull.




On 5/13/05, Mark Dillon <[EMAIL PROTECTED]> wrote:
> Perfect!  Thank you very much.  Are those examples out there anywhere?
>  BTW, love Lucene in Action...
> 
> Thanks,
> Mark
> 
> On 5/13/05, Erik Hatcher <[EMAIL PROTECTED]> wrote:
> > On May 12, 2005, at 11:53 PM, Mark Dillon wrote:
> >
> > > Has anyone out there attempted to dynamically load a page template
> > > from the database at runtime?  For instance, imagine I had a model
> > > property on a page specification, and that model had a string property
> > > containing template text.  Would it be possible to render this as the
> > > page template (or component template for that matter)?  I know this
> > > has been touched on by a few people, but I haven't found any solid
> > > examples for doing it.  Just wanted to see if anyone had attempted
> > > this before re-inventing the proverbial wheel...
> >
> > I have done prototype examples of this.  The plumbing is in place.
> > In Tapestry 3.0 (and surely 4.0 also) you can create an
> > ITemplateSourceDelegate and register it as an <extension> in
> > your .application file.  Any time a template cannot be found in the
> > web application where its supposed to be by default, it will ask your
> > delegate for it.
> >
> > This, in my opinion, is one of Tapestry's greatest (but relatively
> > unknown) strengths!
> >
> >      Erik
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to