You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Borut Bolčina <bo...@gmail.com> on 2009/05/14 10:45:37 UTC

Setting component type at runtime

Hi,

I am trying to set the layout dynamically, but I guess this can not be done.
The t:type="${layout}" does not get expanded to whatever I set in
Index.java.

PageWithLayout.tml
===============
<div t:type="${layout}" xmlns:t="
http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
    <p>page with ${layout}</p>
</div>

PageWithLayout.java
===============
public class PageWithLayout {

    private String layout;

    public String getLayout() {
        return layout;
    }

    public void setLayout(String layout) {
        this.layout = layout;
    }
}

Index.tml
=======
<t:actionlink t:id="PageWithLayout1">layout1</t:actionlink><br/>
<t:actionlink t:id="PageWithLayout2">layout2</t:actionlink>

Index.java
=======
public class Index {
    @InjectPage
    private PageWithLayout pageWithLayout;

    Object onActionFromPageWithLayout1() {
        pageWithLayout.setLayout("layout1");
        return pageWithLayout;
    }

    Object onActionFromPageWithLayout2() {
        pageWithLayout.setLayout("layout2");
        return pageWithLayout;
    }
}

-Borut

Re: Setting component type at runtime

Posted by Ulrich Stärk <ul...@spielviel.de>.
Something like that, yeah.

Am 14.05.2009 12:12 schrieb Borut Bolčina:
> You probably mean that I would have one layout component, but with
> conditional blocks and not several layouts chosen dynamically?
> 
> -Borut
> 
> 2009/5/14 Ulrich Stärk <ul...@spielviel.de>
> 
>> Maybe a Delegate can help you here.
>>
>> Uli
>>
>> Am 14.05.2009 10:45 schrieb Borut Bolčina:
>>
>>  Hi,
>>> I am trying to set the layout dynamically, but I guess this can not be
>>> done.
>>> The t:type="${layout}" does not get expanded to whatever I set in
>>> Index.java.
>>>
>>> PageWithLayout.tml
>>> ===============
>>> <div t:type="${layout}" xmlns:t="
>>> http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
>>>    <p>page with ${layout}</p>
>>> </div>
>>>
>>> PageWithLayout.java
>>> ===============
>>> public class PageWithLayout {
>>>
>>>    private String layout;
>>>
>>>    public String getLayout() {
>>>        return layout;
>>>    }
>>>
>>>    public void setLayout(String layout) {
>>>        this.layout = layout;
>>>    }
>>> }
>>>
>>> Index.tml
>>> =======
>>> <t:actionlink t:id="PageWithLayout1">layout1</t:actionlink><br/>
>>> <t:actionlink t:id="PageWithLayout2">layout2</t:actionlink>
>>>
>>> Index.java
>>> =======
>>> public class Index {
>>>    @InjectPage
>>>    private PageWithLayout pageWithLayout;
>>>
>>>    Object onActionFromPageWithLayout1() {
>>>        pageWithLayout.setLayout("layout1");
>>>        return pageWithLayout;
>>>    }
>>>
>>>    Object onActionFromPageWithLayout2() {
>>>        pageWithLayout.setLayout("layout2");
>>>        return pageWithLayout;
>>>    }
>>> }
>>>
>>> -Borut
>>>
>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
> 


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


Re: Setting component type at runtime

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Thu, 14 May 2009 15:32:20 -0300, Borut Bolčina  
<bo...@gmail.com> escreveu:

> My intention was that page selects its own layout, not which block gets
> rendered. I am using the block and delegate for other purposes. If the
> layouts don't differ much then one can use parameters for the layout and
> then conditionally renders parts of the layout so it looks different. I
> wanted to have several simple layouts which a page can choose for itself,
> which I think is more "clean" then having one with a lot of blocks and  
> ifs.

I would create a Layout component with some parameters set by each page.  
Then the blocks and the Delegate are used inside Layout. ;)

-- 
Thiago H. de Paula Figueiredo
Consultor, desenvolvedor e instrutor em Java
http://www.arsmachina.com.br/thiago

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


Re: Setting component type at runtime

Posted by Borut Bolčina <bo...@gmail.com>.
My intention was that page selects its own layout, not which block gets
rendered. I am using the block and delegate for other purposes. If the
layouts don't differ much then one can use parameters for the layout and
then conditionally renders parts of the layout so it looks different. I
wanted to have several simple layouts which a page can choose for itself,
which I think is more "clean" then having one with a lot of blocks and ifs.

-Borut

2009/5/14 Thiago H. de Paula Figueiredo <th...@gmail.com>

> On Thu, May 14, 2009 at 7:12 AM, Borut Bolčina <bo...@gmail.com>
> wrote:
> > You probably mean that I would have one layout component, but with
> > conditional blocks and not several layouts chosen dynamically?
>
> Not exactly. You can define one block per layout and use delegate to
> render one of them. The choosing logic stays in the page class.
> There's one example here:
>
> http://tapestry.apache.org/tapestry5.1/tapestry-core/ref/org/apache/tapestry5/corelib/components/Delegate.html
>
> --
> Thiago
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: Setting component type at runtime

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Thu, May 14, 2009 at 7:12 AM, Borut Bolčina <bo...@gmail.com> wrote:
> You probably mean that I would have one layout component, but with
> conditional blocks and not several layouts chosen dynamically?

Not exactly. You can define one block per layout and use delegate to
render one of them. The choosing logic stays in the page class.
There's one example here:
http://tapestry.apache.org/tapestry5.1/tapestry-core/ref/org/apache/tapestry5/corelib/components/Delegate.html

-- 
Thiago

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


Re: Setting component type at runtime

Posted by Borut Bolčina <bo...@gmail.com>.
You probably mean that I would have one layout component, but with
conditional blocks and not several layouts chosen dynamically?

-Borut

2009/5/14 Ulrich Stärk <ul...@spielviel.de>

> Maybe a Delegate can help you here.
>
> Uli
>
> Am 14.05.2009 10:45 schrieb Borut Bolčina:
>
>  Hi,
>>
>> I am trying to set the layout dynamically, but I guess this can not be
>> done.
>> The t:type="${layout}" does not get expanded to whatever I set in
>> Index.java.
>>
>> PageWithLayout.tml
>> ===============
>> <div t:type="${layout}" xmlns:t="
>> http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
>>    <p>page with ${layout}</p>
>> </div>
>>
>> PageWithLayout.java
>> ===============
>> public class PageWithLayout {
>>
>>    private String layout;
>>
>>    public String getLayout() {
>>        return layout;
>>    }
>>
>>    public void setLayout(String layout) {
>>        this.layout = layout;
>>    }
>> }
>>
>> Index.tml
>> =======
>> <t:actionlink t:id="PageWithLayout1">layout1</t:actionlink><br/>
>> <t:actionlink t:id="PageWithLayout2">layout2</t:actionlink>
>>
>> Index.java
>> =======
>> public class Index {
>>    @InjectPage
>>    private PageWithLayout pageWithLayout;
>>
>>    Object onActionFromPageWithLayout1() {
>>        pageWithLayout.setLayout("layout1");
>>        return pageWithLayout;
>>    }
>>
>>    Object onActionFromPageWithLayout2() {
>>        pageWithLayout.setLayout("layout2");
>>        return pageWithLayout;
>>    }
>> }
>>
>> -Borut
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: Setting component type at runtime

Posted by Ulrich Stärk <ul...@spielviel.de>.
Maybe a Delegate can help you here.

Uli

Am 14.05.2009 10:45 schrieb Borut Bolčina:
> Hi,
> 
> I am trying to set the layout dynamically, but I guess this can not be done.
> The t:type="${layout}" does not get expanded to whatever I set in
> Index.java.
> 
> PageWithLayout.tml
> ===============
> <div t:type="${layout}" xmlns:t="
> http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
>     <p>page with ${layout}</p>
> </div>
> 
> PageWithLayout.java
> ===============
> public class PageWithLayout {
> 
>     private String layout;
> 
>     public String getLayout() {
>         return layout;
>     }
> 
>     public void setLayout(String layout) {
>         this.layout = layout;
>     }
> }
> 
> Index.tml
> =======
> <t:actionlink t:id="PageWithLayout1">layout1</t:actionlink><br/>
> <t:actionlink t:id="PageWithLayout2">layout2</t:actionlink>
> 
> Index.java
> =======
> public class Index {
>     @InjectPage
>     private PageWithLayout pageWithLayout;
> 
>     Object onActionFromPageWithLayout1() {
>         pageWithLayout.setLayout("layout1");
>         return pageWithLayout;
>     }
> 
>     Object onActionFromPageWithLayout2() {
>         pageWithLayout.setLayout("layout2");
>         return pageWithLayout;
>     }
> }
> 
> -Borut
> 


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