You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Alexandros Karypidis <ak...@yahoo.gr> on 2011/01/26 22:38:38 UTC

Modify element attribute, preserve content

Hello,

I have the following case which I do not know how to handle with Wicket:

I have an element (specifically it is an <a href="">...</a> link) for which I 
need to generate an attribute's value dynamically (specifically, I need to set 
the "href" attribute at runtime), but I need to preserve the static content of 
the page.

For example, my HTML file is:

<a wicket:id="myTarget"><span class="x"></span>some static text</a>

What do I have to do to produce:

<a href="dynamically generated target"><span class="x"></span>some static 
text</a>

So far, I've always replaced the entire content of an element with that 
generated by some wicket component, but this is the first time I've needed to 
"filter" part of the DOM and target something very specific in the middle of the 
tree, without affecting the rest of the tree...




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


Re: Modify element attribute, preserve content

Posted by Bas Gooren <ba...@iswd.nl>.
Use a WebMarkupContainer and add a SimpleAttributeModifier behavior to 
it. It will not touch the contents of the tag it's attached to, leaving 
your own html as it is.

Bas

Op 26-1-2011 22:38, Alexandros Karypidis schreef:
> Hello,
>
> I have the following case which I do not know how to handle with Wicket:
>
> I have an element (specifically it is an<a href="">...</a>  link) for which I
> need to generate an attribute's value dynamically (specifically, I need to set
> the "href" attribute at runtime), but I need to preserve the static content of
> the page.
>
> For example, my HTML file is:
>
> <a wicket:id="myTarget"><span class="x"></span>some static text</a>
>
> What do I have to do to produce:
>
> <a href="dynamically generated target"><span class="x"></span>some static
> text</a>
>
> So far, I've always replaced the entire content of an element with that
> generated by some wicket component, but this is the first time I've needed to
> "filter" part of the DOM and target something very specific in the middle of the
> tree, without affecting the rest of the tree...
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>

Re: Modify element attribute, preserve content

Posted by Bas Gooren <ba...@iswd.nl>.
Or, come to think of it, since you want to generate a href yourself on a 
link tag, use ExternalLink 
<http://wicket.apache.org/apidocs/1.4/org/apache/wicket/markup/html/link/ExternalLink.html>. 
Since it's a WebMarkupContainer underneath it will leave whatever is 
inside your a-tag intact.

Bas

Op 26-1-2011 22:38, Alexandros Karypidis schreef:
> Hello,
>
> I have the following case which I do not know how to handle with Wicket:
>
> I have an element (specifically it is an<a href="">...</a>  link) for which I
> need to generate an attribute's value dynamically (specifically, I need to set
> the "href" attribute at runtime), but I need to preserve the static content of
> the page.
>
> For example, my HTML file is:
>
> <a wicket:id="myTarget"><span class="x"></span>some static text</a>
>
> What do I have to do to produce:
>
> <a href="dynamically generated target"><span class="x"></span>some static
> text</a>
>
> So far, I've always replaced the entire content of an element with that
> generated by some wicket component, but this is the first time I've needed to
> "filter" part of the DOM and target something very specific in the middle of the
> tree, without affecting the rest of the tree...
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>