You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Michael Brinkman <mi...@gmail.com> on 2010/08/15 15:40:09 UTC

Swapping a wicket rendered tag for an alternate tag or text

My apologies if this has been answered a thousand times before but I haven't
been able to find anything in searching, so your thoughts would be
appreciated.

I have a very simple scenario where I have an anchor tag associated with a
wicket link that wraps a static image like this:

<a wicket:id="myLink">Link Text</a>

In some cases, I would like to swap this anchor tag and it's body with a
&nbsp; since it's in a table.  So I've used setEnabled(false) on the
associated Link instance to cause the anchor tag to be swapped with a span
and then I overrode the onComponentTagBody method on the Link like so:

                protected void onComponentTagBody(MarkupStream markupStream,
ComponentTag openTag)
                {
                    //    Only render the body if the link is enabled
                    if (this.isEnabled())
                    {
                        super.onComponentTagBody(markupStream, openTag);
                    }
                    else
                    {
                        //    Write out a space and then move to the
matching close tag of the original link.  Even though
                        //    the open tag has been renamed to "span" by
being disabled, the framework will take care of renaming the
                        //    close tag as well.
                        getResponse().write("&nbsp;");
                        markupStream.skipToMatchingCloseTag(openTag);
                    }
                }

So what comes out is a little more verbose than just a non breaking space:

<span>&nbsp;</span>

Any thoughts on a better approach to this would be appreciated. I'm really
interested in this because I find it to be a generally useful thing to know
how to do and I suspect there's probably already a simpler way to swap a
wicket rendered tag for something else that I just don't know about.

Thanks,

-Michael

Re: Swapping a wicket rendered tag for an alternate tag or text

Posted by Uwe Schäfer <us...@thomas-daily.de>.
On 08/15/2010 03:40 PM, Michael Brinkman wrote:

> In some cases, I would like to swap this anchor tag and it's body with a
> &nbsp; since it's in a table.

to get rid of the span-tag, see

setRenderBodyOnly(true);

cu uwe

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


Re: Swapping a wicket rendered tag for an alternate tag or text

Posted by gmail <kj...@gmail.com>.
You just add both the link and the text to your page with setVisible(false).
Then setVisible(true) on the one you want to show.

Regards,
kjarbr

 


On 15.08.10 15.40, "Michael Brinkman" <mi...@gmail.com> wrote:

> My apologies if this has been answered a thousand times before but I haven't
> been able to find anything in searching, so your thoughts would be
> appreciated.
> 
> I have a very simple scenario where I have an anchor tag associated with a
> wicket link that wraps a static image like this:
> 
> <a wicket:id="myLink">Link Text</a>
> 
> In some cases, I would like to swap this anchor tag and it's body with a
> &nbsp; since it's in a table.  So I've used setEnabled(false) on the
> associated Link instance to cause the anchor tag to be swapped with a span
> and then I overrode the onComponentTagBody method on the Link like so:
> 
>                 protected void onComponentTagBody(MarkupStream markupStream,
> ComponentTag openTag)
>                 {
>                     //    Only render the body if the link is enabled
>                     if (this.isEnabled())
>                     {
>                         super.onComponentTagBody(markupStream, openTag);
>                     }
>                     else
>                     {
>                         //    Write out a space and then move to the
> matching close tag of the original link.  Even though
>                         //    the open tag has been renamed to "span" by
> being disabled, the framework will take care of renaming the
>                         //    close tag as well.
>                         getResponse().write("&nbsp;");
>                         markupStream.skipToMatchingCloseTag(openTag);
>                     }
>                 }
> 
> So what comes out is a little more verbose than just a non breaking space:
> 
> <span>&nbsp;</span>
> 
> Any thoughts on a better approach to this would be appreciated. I'm really
> interested in this because I find it to be a generally useful thing to know
> how to do and I suspect there's probably already a simpler way to swap a
> wicket rendered tag for something else that I just don't know about.
> 
> Thanks,
> 
> -Michael



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