On Thu, Apr 12, 2018 at 1:52 PM, Carlos Montero Canabal <
carlosmonterocana...@gmail.com> wrote:

> Hi tapestry users,


Being pedantic and accurate, the subject line of your e-mail is incorrect:
Tapestry 5 doesn't support adding components dynamically to a page or
component. The structure of pages and components are strictly static. You
need to declare a component in a template in order to use it. There are no

On the other hand, you have all the freedom to run your templates in any
way you choose, with logic dictating what gets actually rendered.

> I’m developing a configurable dashboard page where a user can select
> different widgets to his own dashboard. I’m thinking on save on database
> the widgets with his configuration per user. I would like to do something
> like this:
> <t:loop source="widgets" value="widget">
>         <t:delegate to=“createWidget”/>
> </t:loop>
> And in my page class something like:
> public Block getCreateWidget(){
>         return componentSource.getComponent(widget.getComponentClassName());
> <!-— This method “getComponent” by name/class doesn´t exists, only for
> logical page names —>
> }
> Where widget.getComponentClassName() returns, for example,
> "components/Widget1” or “my.package.components.Widget1".
> Do you know if it’s possible this approach on Tapestry5?? With pages it
> works fine (I do it multiple times for email rendering), but with
> components I don’t found a method o service…

Using the Delegate component to dynamically choose which Block or component
instance to render is correct. On the other hand, the getCreateWidget()
method as described above won't work at all.

What actually works is declaring <t:block>s in a page, using
ComponentSource.getPage() to get an instance of that page, which is
returned as a Component instance, then calling
getComponentResources().getBlock(String id) to get the Block instance to
pass to the Delegate component. That's exactly how the BeanModel-based
components, such as Grid, BeanEditor, BeanDisplay and BeanEditForm work.

> Thank you everyone
> Best regards
> Carlos Montero
> http://tapestry5.dev-util.com/ <http://tapestry5.dev-util.com/>


Reply via email to