Dynamic page templates?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Dynamic page templates?

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

Cheers,
Mark

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Dynamic page templates?

Jun Tsai
try DynamicBlock

On 5/13/05, Mark Dillon <[hidden email]> 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...
>
> Cheers,
> Mark
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


--
Welcome to China Java Users Group(CNJUG).
http://cnjug.dev.java.net

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Dynamic page templates?

Erik Hatcher
In reply to this post by Mark Dillon
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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Dynamic page templates?

Mark Dillon
Perfect!  Thank you very much.  Are those examples out there anywhere?
 BTW, love Lucene in Action...

Thanks,
Mark

On 5/13/05, Erik Hatcher <[hidden email]> 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: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Dynamic page templates?

Erik Hatcher

On May 13, 2005, at 12:19 PM, Mark Dillon wrote:

> Perfect!  Thank you very much.  Are those examples out there anywhere?

I've posted some things to this list, so check the archives and see  
if you can turn it up.  Searching for ITemplateSourceDelegate ought  
to get you there.

>  BTW, love Lucene in Action...

Thanks!!!!  Always a joy to hear.

     Erik


>
> Thanks,
> Mark
>
> On 5/13/05, Erik Hatcher <[hidden email]> 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: [hidden email]
>> For additional commands, e-mail: tapestry-user-
>> [hidden email]
>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Dynamic page templates?

Pablo Ruggia
In reply to this post by Mark Dillon
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 <[hidden email]> 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 <[hidden email]> 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: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]