You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by dpmihai <dp...@yahoo.com> on 2012/04/10 09:29:56 UTC
ContextImage and tooltip behavior
I want to add a tooltip behavior to a ContextImage in Wicket 1.5.5.
public class SimpleTooltipBehavior extends Behavior{
private String tooltip;
public SimpleTooltipBehavior(String tooltip) {
super();
this.tooltip = tooltip;
}
@Override
public void onComponentTag(Component component, ComponentTag tag) {
super.onComponentTag(component, tag);
tag.addBehavior(AttributeModifier.replace("alt", tooltip));
tag.addBehavior(AttributeModifier.replace("title", tooltip));
}
}
This does not work. The modifiers are not added to the markup.
But this works:
public class SimpleTooltipBehavior extends Behavior{
private String tooltip;
public SimpleTooltipBehavior(String tooltip) {
super();
this.tooltip = tooltip;
}
@Override
public void onComponentTag(Component component, ComponentTag tag) {
super.onComponentTag(component, tag);
tag.getAttributes().put("alt", tooltip);
tag.getAttributes().put("title", tooltip);
}
}
What is wrong with the first code?
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/ContextImage-and-tooltip-behavior-tp4544817p4544817.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: ContextImage and tooltip behavior
Posted by Martin Grigorov <mg...@apache.org>.
Hi,
On Tue, Apr 10, 2012 at 9:29 AM, dpmihai <dp...@yahoo.com> wrote:
> I want to add a tooltip behavior to a ContextImage in Wicket 1.5.5.
>
> public class SimpleTooltipBehavior extends Behavior{
>
> private String tooltip;
>
> public SimpleTooltipBehavior(String tooltip) {
> super();
> this.tooltip = tooltip;
> }
>
> @Override
> public void onComponentTag(Component component, ComponentTag tag) {
> super.onComponentTag(component, tag);
> tag.addBehavior(AttributeModifier.replace("alt", tooltip));
> tag.addBehavior(AttributeModifier.replace("title", tooltip));
> }
> }
>
> This does not work. The modifiers are not added to the markup.
>
> But this works:
>
> public class SimpleTooltipBehavior extends Behavior{
>
> private String tooltip;
>
> public SimpleTooltipBehavior(String tooltip) {
> super();
> this.tooltip = tooltip;
> }
>
> @Override
> public void onComponentTag(Component component, ComponentTag tag) {
> super.onComponentTag(component, tag);
> tag.getAttributes().put("alt", tooltip);
> tag.getAttributes().put("title", tooltip);
> }
>
> }
>
> What is wrong with the first code?
ComponentTag's behaviors are used/read before component's
behavior#onComponentTag() is called. I.e. you add them a bit late.
You can do it with:
public class SimpleTooltipBehavior extends Behavior{
private String tooltip;
public SimpleTooltipBehavior(String tooltip) {
super();
this.tooltip = tooltip;
}
@Override
public void onBind(Component component) {
component.add(AttributeModifier.replace("alt", tooltip));
component.add(AttributeModifier.replace("title", tooltip));
}
>
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/ContextImage-and-tooltip-behavior-tp4544817p4544817.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
--
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org