Hi,
On Tue, Apr 10, 2012 at 9:29 AM, dpmihai <[email protected]> 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: [email protected]
> For additional commands, e-mail: [email protected]
>
--
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]