You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Michael <ga...@gmail.com> on 2014/08/29 09:23:30 UTC
How to get current element in mixin
I need a mixin which can be attached to different elements (with and
without body). The mixin wraps original element with another and adds some
classes to the original. How I can get current element while render? I'd
use writer.getElement() in render body but its not triggered in components
with empty body. In begin render phase writer returns container instead of
current element.
Re: How to get current element in mixin
Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
There's another solution, but it just works when the component is a
ClientElement:
@MixinAfter
public class MyMixin {
@InjectContainer
private ClientElement clientElement;
void afterRender(MarkupWriter writer) {
Element element = writer.getElementById(clientElement.getClientId());
}
}
I have not tested the code above.
On Fri, 29 Aug 2014 06:04:18 -0300, Lance Java <la...@googlemail.com>
wrote:
> @MixinAfter
> public class MyMixin {
> void afterRender(MarkupWriter writer) {
> List<Node> children = writer.getElement().getChildren();
> if (!children.isEmpty()) {
> Element lastChild = (Element) children.get(children.size() - 1);
> doStuff(lastChild);
> }
> }
> }
--
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: How to get current element in mixin
Posted by Lance Java <la...@googlemail.com>.
@MixinAfter
public class MyMixin {
void afterRender(MarkupWriter writer) {
List<Node> children = writer.getElement().getChildren();
if (!children.isEmpty()) {
Element lastChild = (Element) children.get(children.size() - 1);
doStuff(lastChild);
}
}
}