I've done exactly what you say. Plus some things like dinamically change of 
layout (something like swing). You can make this magic happen using 
ITemplateSourceDelegate. You can also generate dynamic page specification. 
I have to tell you, it's not that easy. In fact, i am rewriting the code to 
make it work without tapestry. It was really a headache. I don't recommend 
you to start creating this.
But, if you want to try, I am sending you some part of the code i've posted 
to the list before. Here it is:

****************
To create dynamic html templates
*****************
Pablo Ruggia <[EMAIL PROTECTED]> wrote:
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(templateChar s,
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.

****************************** ********
To generate dinamic .page specifications
**************************************

I'm working on a set of classes that generate the templates for pages
"on-the-fly" using a configurable layout.
To do that I have to make it work without .html files and without
.page files. Here is what i've done:

1) To create Specifications without specification files, I create a
class that implements ISpecificationResolverDelegate , and then I
register in the .application file a extension in this way:

<extension name="org.apache.tapestry.specification-resolver-delegate"
class="fullPackage.MyDelegator" /> 

MyDelegator has to implement a method named findPageSpecification()
which returns an IComponentSpecification. Here is an example of this
method:

public synchronized final IComponentSpecification
findPageSpecification( IRequestCycle cycle, INamespace 
namespace, String simplePageName) {

Class pageClass =
aMethodWichResolvesPageClassBasingOnPageName(simplePageName);

IComponentSpecification pageSpec = new ComponentSpecification();

pageSpec.setComponentClassName (pageClass.getName());

IResourceLocation applicationLocation = namespace.getSpecificationLocation
();

pageSpec.setSpecificationLocation(location);

return pageSpec;

}

 






On 7/19/05, Tapestry Fan <[EMAIL PROTECTED]> wrote:
> 
> I have been seeing the Trails video, it´s very good.., but it´s powerfull 
> to
> creat pages that manage the insert, update, and delete data from the
> database. I was thinking in creat classes that can generate the html for 
> the
> placeholders of the components, as well as its specification on-the-fly, 
> and
> create a class that can hold that objects (those that generate the html 
> for
> the components) called the container.
> so i want to do something like this...
> 
> public class mypage extends BasePage{
> 
> public char[] getTemplate(){
> 
> Container container = new Container();
> 
> Component component = new InsertComponent("StringtoPass",....); //in this
> method i want to pass all the parameters that an insert component can
> manipulate, those formal and informal.
> 
> container.addComponent(component); //add the component to the container
> 
> char[] TemplateChars = container.getTemplate().toChars(); //the method
> getTemplate for the container will generate on-the-fly the htlm (it is a
> component too and have other components - composite pattern) and the html
> for all the components it have in.
> 
> return TemplateChars;
> 
> }
> 
> }
> 
> what you think about this. is a good idea?
> 
> Tell me if you think something like this.
> 
> On 7/19/05, Tapestry Fan <[EMAIL PROTECTED]> wrote:
> >
> > Sorry Robert, i send the message and i thought that it coundn´t be
> > read..., it won´t happen again.
> >
> > On 7/19/05, Robert Zeigler < [EMAIL PROTECTED]> wrote:
> > >
> > > 1) Please don't cross-post or multiple post; personally, this is the
> > > third time I've seen this message in the last 24 hours. That gets
> > > really old really fast.
> > > 2) Check out trails: https://trails.dev.java.net/ which is already 
> doing
> > > what you describe.
> > >
> > > Robert
> > >
> > > Tapestry Fan wrote:
> > > > Hello everyone!
> > > >
> > > > I want to develop a set of classes to dinamically generate the html
> > > > template. I want to do some predefined templates and i want to make
> > > > some classes that can construct the components templates and the
> > > > specification of that components. I think this beacouse the mayority
> > > > of the screens in a web application can be reused to other web
> > > > application, so i want to automate the generation of the html to
> > > > develop applications in very much less time.
> > > > I was thinking in using the composite pattern and make a class for
> > > > every component to generate the template corresponding to that
> > > > component, and other class that can hold the components like a
> > > > container. then my idea is to have a collection of containers in a
> > > > page and composite in every container all the components i want.
> > > >
> > > > Have you got any idea to this? i mean, you think i´m in the right 
> way
> > > > using the composite pattern and the panel class or you have other
> > > > ideas?
> > > >
> > > > Thanks a lot!
> > > >
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > For additional commands, e-mail: [EMAIL PROTECTED]
> > >
> > >
> >
> 
>

Reply via email to