You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Lukasz Jazgar <lu...@gmail.com> on 2009/06/05 17:53:13 UTC

Decoration passed by parameter. Possible?

Hi,

Is it possible in Tapestry to pass by parameter to component piece of
html, by which component will surround some part of it?

Regards
Lukasz

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


Re: Decoration passed by parameter. Possible?

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Fri, 05 Jun 2009 13:33:31 -0300, Lukasz Jazgar  
<lu...@gmail.com> escreveu:

> Are render phase methods normal events? Are they bubbled to container  
> component?

No. No. But components can trigger their own events.

-- 
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
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: Decoration passed by parameter. Possible?

Posted by Lukasz Jazgar <lu...@gmail.com>.
2009/6/5 Thiago H. de Paula Figueiredo <th...@gmail.com>:
> On Fri, Jun 5, 2009 at 12:53 PM, Lukasz Jazgar<lu...@gmail.com> wrote:
>
>> Is it possible in Tapestry to pass by parameter to component piece of
>> html, by which component will surround some part of it?
>
> Take a look at the component render lifecycle, the MarkupWriter
> interface and mixins. Maybe you'll find your answer there.

Are render phase methods normal events? Are they bubbled to container component?

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


Re: Decoration passed by parameter. Possible?

Posted by Lukasz Jazgar <lu...@gmail.com>.
Great!
I'm impressed by simplicity of this solution and by power of Tapestry, again.
Thanks a lot.

Lukasz

2009/6/10 DH <ni...@gmail.com>:
> Well, a simple implementation here may be like:
>
> public class Decorate {
>    @Parameter(required = true)
>    private Object by;
>
>    @Inject
>    private ComponentResources componentResources;
>
>    @Inject
>    private Environment environment;
>
>    Object beginRender()
>    {
>        environment.push(Block.class, componentResources.getBody());
>        return by;
>    }
>
>    // in your case, should not render the body, orelse there will be two cases rendered.
>    boolean beforeRenderBody() {
>        return false;
>    }
> }
>
> public class DecoratedBody {
>
>    @Inject
>    private Environment environment;
>
>    Object beginRender()
>    {
>        return environment.peek(Block.class);
>    }
> }
>
>
> I've test and it works.
> <div t:type="complexcomponent">
>  <p:titleDecorator>
>  aaa <t:decoratedBody/> bbb
>  </p:titleDecorator>
> </div>
>
> <div t:type="complexcomponent">
>  <p:titleDecorator>
>  <t:pageLink page="index"><t:decoratedBody/></t:pageLink> </p:titleDecorator>
> </div>
>
> They all work and show what I need.
>
> DH
>
> ----- Original Message -----
> From: "Lukasz Jazgar" <lu...@gmail.com>
> To: "Tapestry users" <us...@tapestry.apache.org>
> Sent: Saturday, June 06, 2009 5:24 AM
> Subject: Re: Decoration passed by parameter. Possible?
>
>
> 2009/6/5 Lukasz Jazgar <lu...@gmail.com>:
>> Suppose, I have a component:
>>
>> ComplexComponent.tml
>> <div>
>> ...
>> a lot of tags and components
>> ...
>> <span id="title">
>> .. complex content ..
>> </div>
>> ...
>> a lot of other tags and components
>> ...
>> </div>
>>
>> ComplexComponent is very usefull. I use it repeatedly on pages. BUT in
>> some cases I need "title" to be hyperlink to Tapestry page, in other
>> cases hyperlink to another page, sometimes external hyperlink or
>> "mailto:" link. In other cases I need decorate it by border, complex
>> and unrealizable by only CSS. And finally, I'd like to have
>> possibility to define any other surrounding of title in the future,
>> preferably without changing ComplexComponent.
>>
>
> I imagine such a solution:
>
> ComplexComponent.java
> @Parameter
> @Property
> Block titleDecorator;
>
> ComplexComponent.tml
> <div>
>  ...
>  a lot of tags and components
>  ...
>    <t:decorate by="titleDecorator">
>          <span id="title">
>              .. complex content ..
>          </div>
>    </t:decorate>
>  ...
>  a lot of other tags and components
>  ...
> </div>
>
> Page.tml
> <t:complexComponent>
>   <t:titleDecorator>
>        <t:pageLink page="otherPage"><t:decoratedBody/></t:pageLink>
>   </t:titleDecorator>
> </t:complexComponent>
>
> Legend:
> decorate - component a little bit similar to delagate
> <t:decoratedBody/> - special tag like <t:body/> but relative to
> containing Block.
>
> It's a pity, that it is only imagination.
> Is it possible to do something similar now?
> If not, is it technically possible to make such a improvement in
> future versions? It would be very powerful feature.
>
>
> Lukasz
>
> ---------------------------------------------------------------------
> 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: Decoration passed by parameter. Possible?

Posted by Sergey Didenko <se...@gmail.com>.
Thanks.

On Sat, Jun 13, 2009 at 4:06 AM, Lukasz Jazgar<lu...@gmail.com> wrote:
> 2009/6/12 Sergey Didenko <se...@gmail.com>:
>> Could you help me, I can't understand how it is wired together.
>>
>> What is passed as its "by" parameter.
>
> Generally, Block with <t:decoratedBody/> inside, which I name "decorator".
>
>> Where the class Decorate is used?
>
> Take a look at my former post.
>
> Page.tml has ComplexComponent and passes to it block (="decorator") by
> "titleDecorator" parameter.
> Inside ComplexComponent template, there is Decorate component
> surrounding part of template. "Decorator" from "titleDecorator"
> parameter is passed by "by" parameter to Decorate.
> Responsibility of Decorate component is to render its body inside
> block (="decorator") passed by "by" parameter.
>
> If you want, I can send you sources of Decorate and DecoratedBody
> components, a little bit improved against DH's version.
>
> Regards
> Lukasz
>
> ---------------------------------------------------------------------
> 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: Decoration passed by parameter. Possible?

Posted by Lukasz Jazgar <lu...@gmail.com>.
2009/6/12 Sergey Didenko <se...@gmail.com>:
> Could you help me, I can't understand how it is wired together.
>
> What is passed as its "by" parameter.

Generally, Block with <t:decoratedBody/> inside, which I name "decorator".

> Where the class Decorate is used?

Take a look at my former post.

Page.tml has ComplexComponent and passes to it block (="decorator") by
"titleDecorator" parameter.
Inside ComplexComponent template, there is Decorate component
surrounding part of template. "Decorator" from "titleDecorator"
parameter is passed by "by" parameter to Decorate.
Responsibility of Decorate component is to render its body inside
block (="decorator") passed by "by" parameter.

If you want, I can send you sources of Decorate and DecoratedBody
components, a little bit improved against DH's version.

Regards
Lukasz

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


Re: Decoration passed by parameter. Possible?

Posted by Sergey Didenko <se...@gmail.com>.
Could you help me, I can't understand how it is wired together.

Where the class Decorate is used? What is passed as its "by"
parameter. Should "t:complexcomponent" be "t:decorate"?

On Wed, Jun 10, 2009 at 6:57 AM, DH<ni...@gmail.com> wrote:
> Well, a simple implementation here may be like:
>
> public class Decorate {
>    @Parameter(required = true)
>    private Object by;
>
>    @Inject
>    private ComponentResources componentResources;
>
>    @Inject
>    private Environment environment;
>
>    Object beginRender()
>    {
>        environment.push(Block.class, componentResources.getBody());
>        return by;
>    }
>
>    // in your case, should not render the body, orelse there will be two cases rendered.
>    boolean beforeRenderBody() {
>        return false;
>    }
> }
>
> public class DecoratedBody {
>
>    @Inject
>    private Environment environment;
>
>    Object beginRender()
>    {
>        return environment.peek(Block.class);
>    }
> }
>
>
> I've test and it works.
> <div t:type="complexcomponent">
>  <p:titleDecorator>
>  aaa <t:decoratedBody/> bbb
>  </p:titleDecorator>
> </div>
>
> <div t:type="complexcomponent">
>  <p:titleDecorator>
>  <t:pageLink page="index"><t:decoratedBody/></t:pageLink> </p:titleDecorator>
> </div>
>
> They all work and show what I need.
>
> DH
>
> ----- Original Message -----
> From: "Lukasz Jazgar" <lu...@gmail.com>
> To: "Tapestry users" <us...@tapestry.apache.org>
> Sent: Saturday, June 06, 2009 5:24 AM
> Subject: Re: Decoration passed by parameter. Possible?
>
>
> 2009/6/5 Lukasz Jazgar <lu...@gmail.com>:
>> Suppose, I have a component:
>>
>> ComplexComponent.tml
>> <div>
>> ...
>> a lot of tags and components
>> ...
>> <span id="title">
>> .. complex content ..
>> </div>
>> ...
>> a lot of other tags and components
>> ...
>> </div>
>>
>> ComplexComponent is very usefull. I use it repeatedly on pages. BUT in
>> some cases I need "title" to be hyperlink to Tapestry page, in other
>> cases hyperlink to another page, sometimes external hyperlink or
>> "mailto:" link. In other cases I need decorate it by border, complex
>> and unrealizable by only CSS. And finally, I'd like to have
>> possibility to define any other surrounding of title in the future,
>> preferably without changing ComplexComponent.
>>
>
> I imagine such a solution:
>
> ComplexComponent.java
> @Parameter
> @Property
> Block titleDecorator;
>
> ComplexComponent.tml
> <div>
>  ...
>  a lot of tags and components
>  ...
>    <t:decorate by="titleDecorator">
>          <span id="title">
>              .. complex content ..
>          </div>
>    </t:decorate>
>  ...
>  a lot of other tags and components
>  ...
> </div>
>
> Page.tml
> <t:complexComponent>
>   <t:titleDecorator>
>        <t:pageLink page="otherPage"><t:decoratedBody/></t:pageLink>
>   </t:titleDecorator>
> </t:complexComponent>
>
> Legend:
> decorate - component a little bit similar to delagate
> <t:decoratedBody/> - special tag like <t:body/> but relative to
> containing Block.
>
> It's a pity, that it is only imagination.
> Is it possible to do something similar now?
> If not, is it technically possible to make such a improvement in
> future versions? It would be very powerful feature.
>
>
> Lukasz
>
> ---------------------------------------------------------------------
> 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: Decoration passed by parameter. Possible?

Posted by DH <ni...@gmail.com>.
Well, a simple implementation here may be like:

public class Decorate {
    @Parameter(required = true)
    private Object by;

    @Inject
    private ComponentResources componentResources;
    
    @Inject
    private Environment environment;
    
    Object beginRender()
    {
        environment.push(Block.class, componentResources.getBody());
        return by;
    }
    
    // in your case, should not render the body, orelse there will be two cases rendered.
    boolean beforeRenderBody() {
        return false;
    }
}

public class DecoratedBody {

    @Inject
    private Environment environment;
    
    Object beginRender()
    {
        return environment.peek(Block.class);
    }
}


I've test and it works.
<div t:type="complexcomponent">
 <p:titleDecorator>
  aaa <t:decoratedBody/> bbb
 </p:titleDecorator>
</div>

<div t:type="complexcomponent">
 <p:titleDecorator>
  <t:pageLink page="index"><t:decoratedBody/></t:pageLink> </p:titleDecorator>
</div>

They all work and show what I need.

DH

----- Original Message ----- 
From: "Lukasz Jazgar" <lu...@gmail.com>
To: "Tapestry users" <us...@tapestry.apache.org>
Sent: Saturday, June 06, 2009 5:24 AM
Subject: Re: Decoration passed by parameter. Possible?


2009/6/5 Lukasz Jazgar <lu...@gmail.com>:
> Suppose, I have a component:
>
> ComplexComponent.tml
> <div>
> ...
> a lot of tags and components
> ...
> <span id="title">
> .. complex content ..
> </div>
> ...
> a lot of other tags and components
> ...
> </div>
>
> ComplexComponent is very usefull. I use it repeatedly on pages. BUT in
> some cases I need "title" to be hyperlink to Tapestry page, in other
> cases hyperlink to another page, sometimes external hyperlink or
> "mailto:" link. In other cases I need decorate it by border, complex
> and unrealizable by only CSS. And finally, I'd like to have
> possibility to define any other surrounding of title in the future,
> preferably without changing ComplexComponent.
>

I imagine such a solution:

ComplexComponent.java
@Parameter
@Property
Block titleDecorator;

ComplexComponent.tml
<div>
  ...
  a lot of tags and components
  ...
    <t:decorate by="titleDecorator">
          <span id="title">
              .. complex content ..
          </div>
    </t:decorate>
  ...
  a lot of other tags and components
  ...
</div>

Page.tml
<t:complexComponent>
   <t:titleDecorator>
        <t:pageLink page="otherPage"><t:decoratedBody/></t:pageLink>
   </t:titleDecorator>
</t:complexComponent>

Legend:
decorate - component a little bit similar to delagate
<t:decoratedBody/> - special tag like <t:body/> but relative to
containing Block.

It's a pity, that it is only imagination.
Is it possible to do something similar now?
If not, is it technically possible to make such a improvement in
future versions? It would be very powerful feature.


Lukasz

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


Re: Decoration passed by parameter. Possible?

Posted by Lukasz Jazgar <lu...@gmail.com>.
2009/6/5 Lukasz Jazgar <lu...@gmail.com>:
> Suppose, I have a component:
>
> ComplexComponent.tml
> <div>
>   ...
>   a lot of tags and components
>   ...
>           <span id="title">
>               .. complex content ..
>           </div>
>   ...
>   a lot of other tags and components
>   ...
> </div>
>
> ComplexComponent is very usefull. I use it repeatedly on pages. BUT in
> some cases I need "title" to be hyperlink to Tapestry page, in other
> cases hyperlink to another page, sometimes external hyperlink or
> "mailto:" link. In other cases I need decorate it by border, complex
> and unrealizable by only CSS. And finally, I'd like to have
> possibility to define any other surrounding of title in the future,
> preferably without changing ComplexComponent.
>

I imagine such a solution:

ComplexComponent.java
@Parameter
@Property
Block titleDecorator;

ComplexComponent.tml
<div>
  ...
  a lot of tags and components
  ...
    <t:decorate by="titleDecorator">
          <span id="title">
              .. complex content ..
          </div>
    </t:decorate>
  ...
  a lot of other tags and components
  ...
</div>

Page.tml
<t:complexComponent>
   <t:titleDecorator>
        <t:pageLink page="otherPage"><t:decoratedBody/></t:pageLink>
   </t:titleDecorator>
</t:complexComponent>

Legend:
decorate - component a little bit similar to delagate
<t:decoratedBody/> - special tag like <t:body/> but relative to
containing Block.

It's a pity, that it is only imagination.
Is it possible to do something similar now?
If not, is it technically possible to make such a improvement in
future versions? It would be very powerful feature.


Lukasz

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


Re: Decoration passed by parameter. Possible?

Posted by Lukasz Jazgar <lu...@gmail.com>.
2009/6/5 Inge Solvoll <in...@gmail.com>:
> From your explanation, I think you're looking for something like this? This
> should be pretty close to working code.
>
> yourPage.tml:
> <div t:type="yourComponent">
>  <p:param1>
>   Lots of HTML here
>  </p:param1>
> </div>
>
> public class YourComponent {
> @Parameter
> private Block param1;
> }
>
> yourComponent.tml:
> <html>
> <t:delegate to="param1"/>
> </html>
>

Nearly, but not exactly. I'm looking for elastic way to decorate
(=surround by html code) internal part of component. Block passed by
parameter cannot surround anything.

I'll show exactly what i'm looking for by simple example:
Suppose, I have a component:

ComplexComponent.tml
<div>
   ...
   a lot of tags and components
   ...
           <span id="title">
               .. complex content ..
           </div>
   ...
   a lot of other tags and components
   ...
</div>

ComplexComponent is very usefull. I use it repeatedly on pages. BUT in
some cases I need "title" to be hyperlink to Tapestry page, in other
cases hyperlink to another page, sometimes external hyperlink or
"mailto:" link. In other cases I need decorate it by border, complex
and unrealizable by only CSS. And finally, I'd like to have
possibility to define any other surrounding of title in the future,
preferably without changing ComplexComponent.

For now, I know 2 solutions:

1. Huge "if".
Disadvantage: Adding new decoration requires change of
ComplexComponent. Some of decorations can be very simple and can be
used only once. This is the best way to create rubbish component.
Reusabilty of such a component: very low.


2. Passing by parameters texts to place before and after title.
-----------------------------------------------------------------
ComplexComponent.tml
<div>
   ...
   a lot of tags and components
   ...
           <t:outputRaw value="beforeTitle"/>
           <span id="title">
               .. complex content ..
           </div>
           <t:outputRaw value="afterTitle"/>
   ...
   a lot of other tags and components
   ...
</div>
----------------------------------------------------
ComplexComponent.java

...
@Parameter @Property String beforeTitle;
@Parameter @Property String afterTitle;
----------------------------------------------------
Page.tml
...
<t:complexComponent
      beforeTitle="literal:<a href='...'>"
      afterTitle="</a>" />
...
-----------------------------------------------------------------

Awful!!! Disgusting!!!
And components (eg PageLink) cannot be used to render hyperlink. :(


Do you have any better solutions?

Regards
Lukasz

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


Re: Decoration passed by parameter. Possible?

Posted by Inge Solvoll <in...@gmail.com>.
>From your explanation, I think you're looking for something like this? This
should be pretty close to working code.

yourPage.tml:
<div t:type="yourComponent">
  <p:param1>
   Lots of HTML here
  </p:param1>
</div>

public class YourComponent {
@Parameter
private Block param1;
}

yourComponent.tml:
<html>
<t:delegate to="param1"/>
</html>

On Fri, Jun 5, 2009 at 6:01 PM, Thiago H. de Paula Figueiredo <
thiagohp@gmail.com> wrote:

> On Fri, Jun 5, 2009 at 12:53 PM, Lukasz Jazgar<lu...@gmail.com>
> wrote:
> > Hi,
>
> Hi!
>
> > Is it possible in Tapestry to pass by parameter to component piece of
> > html, by which component will surround some part of it?
>
> Take a look at the component render lifecycle, the MarkupWriter
> interface and mixins. Maybe you'll find your answer there.
>
> --
> Thiago
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: Decoration passed by parameter. Possible?

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Fri, Jun 5, 2009 at 12:53 PM, Lukasz Jazgar<lu...@gmail.com> wrote:
> Hi,

Hi!

> Is it possible in Tapestry to pass by parameter to component piece of
> html, by which component will surround some part of it?

Take a look at the component render lifecycle, the MarkupWriter
interface and mixins. Maybe you'll find your answer there.

-- 
Thiago

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