You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Julien Martin <ba...@gmail.com> on 2012/05/04 19:01:24 UTC

Beginner needs help with writing a mixin

Hello,

I am trying to write/code a mixin that will simply add the hreflang
attribute to tapestry action links.

Here is what I tried (it does not work unfortunately...)

public class HrefLangMixin {

@Parameter(name = "lang", required = true, defaultPrefix =
BindingConstants.LITERAL)
private String lang;

// The code
@AfterRender
public void afterRender(MarkupWriter writer) {
Element actionLinkElem = writer.getElement();
System.out.println(actionLinkElem.getChildMarkup());
actionLinkElem.attribute("hreflang", lang);

}
}

<t:actionlink page="ContactUs" t:mixins="HrefLangMixin" t:lang="literal:fr"
context="literal:fr">fr</t:actionlink>

Can anyone please advise?

Regards,

Julien.

Re: Beginner needs help with writing a mixin

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Fri, 04 May 2012 16:29:09 -0300, Julien Martin <ba...@gmail.com> wrote:

> Thanks anyway to both of you. I wrote my first tapestry mixin today!

Congratulations! Mixins are a powerful Tapestry concept which is hard to  
understand at first, but when you do, it becomes simple. :) This moment  
usually comes with that feeling of a lightbulb over your head. :P

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

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


Re: Beginner needs help with writing a mixin

Posted by Julien Martin <ba...@gmail.com>.
Thanks anyway to both of you. I wrote my first tapestry mixin today!
Regards,
Julien.

2012/5/4 Thiago H. de Paula Figueiredo <th...@gmail.com>

> On Fri, 04 May 2012 15:41:50 -0300, Robert Zeigler <
> robert.zeigler@roxanemy.com> wrote:
>
>  Just thinking out loud... not sure why you need a mixin here in the first
>> place? All of tapestry's links support informal parameters. So, eg:
>> <a t:id="mylink" t:type="actionlink" hreflang="fr">Link</a>
>> Should should just work?
>>
>
> Ouch, I completely forgot ActionLink and EventLink support informal
> parameters . . .
>
>
> --
> Thiago H. de Paula Figueiredo
> Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
> and instructor
> Owner, Ars Machina Tecnologia da Informação Ltda.
> http://www.arsmachina.com.br
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.**apache.org<us...@tapestry.apache.org>
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: Beginner needs help with writing a mixin

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Fri, 04 May 2012 15:41:50 -0300, Robert Zeigler  
<ro...@roxanemy.com> wrote:

> Just thinking out loud... not sure why you need a mixin here in the  
> first place? All of tapestry's links support informal parameters. So, eg:
> <a t:id="mylink" t:type="actionlink" hreflang="fr">Link</a>
> Should should just work?

Ouch, I completely forgot ActionLink and EventLink support informal  
parameters . . .

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

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


Re: Beginner needs help with writing a mixin

Posted by Robert Zeigler <ro...@roxanemy.com>.
Just thinking out loud... not sure why you need a mixin here in the first place? All of tapestry's links support informal parameters. So, eg:

<a t:id="mylink" t:type="actionlink" hreflang="fr">Link</a>

Should should just work?

Robert

On May 4, 2012, at 5/412:01 PM , Julien Martin wrote:

> Hello,
> 
> I am trying to write/code a mixin that will simply add the hreflang
> attribute to tapestry action links.
> 
> Here is what I tried (it does not work unfortunately...)
> 
> public class HrefLangMixin {
> 
> @Parameter(name = "lang", required = true, defaultPrefix =
> BindingConstants.LITERAL)
> private String lang;
> 
> // The code
> @AfterRender
> public void afterRender(MarkupWriter writer) {
> Element actionLinkElem = writer.getElement();
> System.out.println(actionLinkElem.getChildMarkup());
> actionLinkElem.attribute("hreflang", lang);
> 
> }
> }
> 
> <t:actionlink page="ContactUs" t:mixins="HrefLangMixin" t:lang="literal:fr"
> context="literal:fr">fr</t:actionlink>
> 
> Can anyone please advise?
> 
> Regards,
> 
> Julien.


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


Re: Beginner needs help with writing a mixin

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Fri, 04 May 2012 14:55:52 -0300, Julien Martin <ba...@gmail.com> wrote:

> Hello Thiago,

Hi!

> Success! It works.

Yay! :D

> Here is what I tried (was not able to understand the forceAttribute()
> syntax...).

A sequence of strings, one attribute name, one attribute value, one  
attribute name, one attribute value, and so on, but for any number of  
(name, value) pairs.

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

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


Re: Beginner needs help with writing a mixin

Posted by Julien Martin <ba...@gmail.com>.
Hello Thiago,

Success! It works.

Here is what I tried (was not able to understand the forceAttribute()
syntax...).

@AfterRender
public void afterRender(MarkupWriter writer) {
String id = clientElement.getClientId();
Element element = writer.getDocument().getElementById(id);
element.attribute("hreflang", lang);
}

Thanks a lot!
Will update the other post/question accordingly.
Regards,
Julien.

2012/5/4 Thiago H. de Paula Figueiredo <th...@gmail.com>

> On Fri, 04 May 2012 14:23:16 -0300, Julien Martin <ba...@gmail.com>
> wrote:
>
>  Hello Thiago,
>>
>
> Hi!
>
>
>  It does display a hreflang but in the "body" tag as follows:
>> <body hreflang="fr">
>>
>
> Ah, ok. :)
>
>
>  It now just boils down to locating the right "a" tag.
>>
>
> I'd try this: give an id (not t:id) to the link and, inside your mixin:
>
> /* ClientElement so your mixin can be used with any component that
> implements this interface, and ActionLink is one of them. */
> @InjectContainer
> private ClientElement clientElement;
>
> void afterRender(MarkupWriter writer) {
>        String id = clientElement.getClientId();
>        Element element = writer.getDocument().**getElementById(id);
>        element.forceAttributes(...);
> }
>
> Please let us know if this works. :)
>
>
> --
> Thiago H. de Paula Figueiredo
> Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
> and instructor
> Owner, Ars Machina Tecnologia da Informação Ltda.
> http://www.arsmachina.com.br
>

Re: Beginner needs help with writing a mixin

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Fri, 04 May 2012 14:23:16 -0300, Julien Martin <ba...@gmail.com> wrote:

> Hello Thiago,

Hi!

> It does display a hreflang but in the "body" tag as follows:
> <body hreflang="fr">

Ah, ok. :)

> It now just boils down to locating the right "a" tag.

I'd try this: give an id (not t:id) to the link and, inside your mixin:

/* ClientElement so your mixin can be used with any component that  
implements this interface, and ActionLink is one of them. */
@InjectContainer
private ClientElement clientElement;

void afterRender(MarkupWriter writer) {
	String id = clientElement.getClientId();
	Element element = writer.getDocument().getElementById(id);
	element.forceAttributes(...);
}

Please let us know if this works. :)

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

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


Re: Beginner needs help with writing a mixin

Posted by Julien Martin <ba...@gmail.com>.
Hello Thiago,

It does display a hreflang but in the "body" tag as follows:

<body hreflang="fr">

It now just boils down to locating the right "a" tag.

Any idea?

Regards,

Julien.

P.S. Sorry for writing to you directly Thiago.



2012/5/4 Julien Martin <ba...@gmail.com>

> Hi,
> It does not display any "hreflang" attribute in the html source...
> Regards,
> Julien.
>
> 2012/5/4 Thiago H. de Paula Figueiredo <th...@gmail.com>
>
> On Fri, 04 May 2012 14:01:24 -0300, Julien Martin <ba...@gmail.com>
>> wrote:
>>
>>  Hello,
>>>
>>
>> Hi!
>>
>>
>>  I am trying to write/code a mixin that will simply add the hreflang
>>> attribute to tapestry action links.
>>>
>>> Here is what I tried (it does not work unfortunately...)
>>>
>>
>> Please define 'it doesn't work'. ;) You seem to be in the right track,
>> probably with just a couple mistakes.
>>
>> --
>> Thiago H. de Paula Figueiredo
>> Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
>> and instructor
>> Owner, Ars Machina Tecnologia da Informação Ltda.
>> http://www.arsmachina.com.br
>>
>
>

Re: Beginner needs help with writing a mixin

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Fri, 04 May 2012 14:01:24 -0300, Julien Martin <ba...@gmail.com> wrote:

> Hello,

Hi!

> I am trying to write/code a mixin that will simply add the hreflang
> attribute to tapestry action links.
>
> Here is what I tried (it does not work unfortunately...)

Please define 'it doesn't work'. ;) You seem to be in the right track,  
probably with just a couple mistakes.

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

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