You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Raoul Zander <rz...@adclear.net> on 2015/01/07 13:01:06 UTC

Add a component to the body of any component

Hi,

I'd like to achieve something like this:

Normal component:
<a href="...">Some text</a>

Enhanced component:
<a href="..."><span class="icon-admin" title="Admin stuff"></span>Some
Text</a>

The span would be the added component.

The link is only an example, in the end it should be possible to 'enhance'
any kind of component. So my first guess was to use a Border or
BorderBehavior- but I couldn't get it to work without extra markup and
classes for each component.
Next guess would have been a custom behavior, but unfortunately there's no
onComponentTagBody, which I would have used to insert arbitrary html code
inside the component.

Right now, I don't see an elegant solution to achieve what I want - but
maybe you could help me?

Something like this would be cool:
anyComponent.add(new IconBehavior(new IconComponent("someId"));
or
anyComponent.add(new IconBehavior(IconComponent.class);

Of course I could just manipulate the rendered HTML of the component like
this:

http://pastebin.com/ECdRmAKG

anyComponent.add(new AbstractTransformerBehavior() {
            public CharSequence transform(Component component, CharSequence
output) {
                // Search output for end of open tag
                // Use org.apache.wicket.core.util.string.ComponentRenderer
to render IconComponent to String
                // insert the rendered string
                return output;
            }
        });

But this is rather quirky.

Kind regards,
Rza

Re: Add a component to the body of any component

Posted by Tobias Soloschenko <to...@googlemail.com>.
Hi,

try to use a WebMarkupContainer (a Link is a WebMarkupContainer so you can add other Components to it with add):

http://wicket.apache.org/guide/guide/keepControl.html#keepControl_4

And wrap "Some Text" into a Label

<a wicket:id="link">
<span wicket:id="adminstuff"/>
<span wicket:id="sometext"/>
</a>

With this solution you can fill adminstuff / sometext with a Label. The normal component is just the Link.

kind regards

Tobias

> Am 07.01.2015 um 13:01 schrieb Raoul Zander <rz...@adclear.net>:
> 
> Hi,
> 
> I'd like to achieve something like this:
> 
> Normal component:
> <a href="...">Some text</a>
> 
> Enhanced component:
> <a href="..."><span class="icon-admin" title="Admin stuff"></span>Some
> Text</a>
> 
> The span would be the added component.
> 
> The link is only an example, in the end it should be possible to 'enhance'
> any kind of component. So my first guess was to use a Border or
> BorderBehavior- but I couldn't get it to work without extra markup and
> classes for each component.
> Next guess would have been a custom behavior, but unfortunately there's no
> onComponentTagBody, which I would have used to insert arbitrary html code
> inside the component.
> 
> Right now, I don't see an elegant solution to achieve what I want - but
> maybe you could help me?
> 
> Something like this would be cool:
> anyComponent.add(new IconBehavior(new IconComponent("someId"));
> or
> anyComponent.add(new IconBehavior(IconComponent.class);
> 
> Of course I could just manipulate the rendered HTML of the component like
> this:
> 
> http://pastebin.com/ECdRmAKG
> 
> anyComponent.add(new AbstractTransformerBehavior() {
>            public CharSequence transform(Component component, CharSequence
> output) {
>                // Search output for end of open tag
>                // Use org.apache.wicket.core.util.string.ComponentRenderer
> to render IconComponent to String
>                // insert the rendered string
>                return output;
>            }
>        });
> 
> But this is rather quirky.
> 
> Kind regards,
> Rza

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