views:

50

answers:

2

I'm learning tapestry 5 web framework but I don't understand the principle 1 about it: "Static Structure, Dynamic Behaviour", what does means it ?

If I don't add components to the components, how can I create a dynamic page?

anyone can help me? Thanks in advance

A: 

Tapestry uses templates to define static content. These templates are usually html pages with placeholder variables which are replaced by some code dynamically by the framework. Templates allow for segregation of things that not change from the ones that change. Usually structure is less prone to change then behavior. Even if you want to change some element of a component dynamically you're going to use some component that itself is defined by a template that is dynamically filled with data. This dynamic data again can insert some other component etc.

Boris Pavlović
+1  A: 

It means that you can't choose or replace components at runtime effectively.

If, say, you'd want to build a portal solution where users could arrange components on a screen any way they wanted, Tapestry would not offer an effective way to do that, because components have static structure, i.e. you must define what goes into them at compile-time in their template file.

Or you might have a specialized menu for administrators, so you might want to just replace the Menu component with a derived component, AdminMenu - but you can't, you have to use if statements in the template or use a block to inject different menus into your layout component.

There's an anti-pattern related to this limitation: The God or über-component tries to solve this problem by effectively having a giant template file with all the available components, like this:

<t:if t:test="displayComponentA">
     <span t:type="ComponentA" ... />
</t:if>
<t:if t:test="displayComponentB">
     <span t:type="ComponentB" ... />
</t:if>
...

This, however, is horribly ineffective, as Tapestry assembles the entire component tree, including components that are not displayed, to do the rendering of the page.

Henning
What happend if I add a textfield on dom tree and receive the value from the request, it violates the principle?
iberck
@iberck: If you do it directly on the DOM, you'll have a hard time processing the submitted value. You can use the FormInjector component to add inputs to a form via AJAX, though: http://tapestry.apache.org/tapestry5/tapestry-core/ref/org/apache/tapestry5/corelib/components/FormInjector.html
Henning
I'm looking for but I don't find examples (only for AjaxFormLoop)May you give me a FormInjector example?
iberck
`AjaxFormLoop` actually uses `FormInjector`. Take a look at `AjaxFormLoop`'s class and template file. Effectively, `FormInjector` renders a DIV with a JavaScript method called `inject()` that you can trigger from your client-side code. It then issues an AJAX request. You must only prodive an AJAX event handler for the `FormInjector`'s "inject" event.
Henning
Thank you Henning, I will find in AjaxFormLoop
iberck