Thank you for your answer Thiago.
I have to create multiple c1,c2,c3,c4,c5,c6,c7,c8,c9 child components of
parentcomponent so I prefer to put the logic inside each component and then
decide which component use with a separate component:
ComponentCase.tml:
<t:delegate to="block"/>
<t:block id="c1">
<t:c1 param1="${param1}" param2="${param2}" param3="${param3}"/>
</t:block>
...
<t:block id="c9">
<t:c9 param1="${param1}" param2="${param2}" param3="${param3}"/>
</t:block>
ComponentCase.java:
public class ComponentCase {
@Parameter(required=true)
@Property
private String param1;
@Parameter(required=true)
@Property
private String param2;
@Parameter(required=true)
@Property
private String param3;
@Inject
private Block c1;
...
@Inject
private Block c9;
public Block getBlock() {
switch (pseudo type) {
case 1:
return c1;
...
case 2:
return c2;
}
}
Test.tml
<t:componentCase param1="1" param2="2" param3="3"/>
What kind of design is better implemented in this case?
Thanks in advance.
On Thu, Feb 6, 2014 at 1:13 PM, Thiago H de Paula Figueiredo <
[email protected]> wrote:
> On Thu, 06 Feb 2014 16:05:04 -0200, iberck <[email protected]> wrote:
>
> hi all,
>>
>
> Hi!
>
>
> how can I transform the next example from inheritance design to
>> composition design ?
>>
>
> You don't even need to have two different components to have a component
> which can have a part of its template replaced:
>
> ParentComponent.tml:
> <t:container xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd"
>
> xmlns:p="tapestry:parameter" t:content="text/html; charset=utf-8">
> this is parent component<br/>
> <t:delegate to="prop:blockToRender"/>
> <t:block id="defaultBlock">default stuff.</t:block>
> </t:container>
>
> ParentComponent.java:
> @SupportsInformalParameters
> public class ParentComponent {
>
> @Parameter(required=true)
> private String param1;
>
> @Parameter(required=true)
> private String param2;
>
> @Parameter(required=true)
> private String param3;
>
> @Parameter(required=true, value="block:defaultBlock")
> private Block blockToRender;
>
> @Inject
> @Property
> private Block defaultBlock;
>
> // getters for parameters
>
> }
>
> When using the component above:
>
> <t:block id="myBlock">
> <t:ParentComponent blockToRender="block:myBlock"/>
>
> --
> Thiago H. de Paula Figueiredo
> Tapestry, Java and Hibernate consultant and developer
> http://machina.com.br
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>