You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Jochen Frey <jo...@jochenfrey.com> on 2012/01/06 02:35:59 UTC

Determine Component Type at Runtime?

It seems like this is a problem others must have encountered so I hope I'm missing something obvious:

I want to be able to pass a component (by name, or by reference) into another component, so that I can decide at runtime what type of component I put into a container component.

Let's say I have a ContainerComponent, and at runtime I want to decide if I render a ContentComponentA, or a ContentComponentB into the container, how do I do that?

I have tried to put variables into the .tml file to determine the type from a variable in the java class like so:  <div t:type=${aType}/>, and that does not work.  It can be done with t:if, but that seems very limiting:

<t:if test="ContentComponentA">
	<div t:type="ContentComponentA"/>
</t:if>
<t:if test="ContentComponentB">
	<div t:type="ContentComponentB"/>
</t:if>


It would be nice if it could be done via formal parameters, or programmatically from the Java side, but I haven't been able to figure it out.

What is the recommended way of doing this?

Thanks so much!
Jochen
---
  jochen@jochenfrey.com
  +1.415.366.0450
  @jochen_frey


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org