On Tue, 22 Jul 2014 07:52:45 -0300, Davide Vecchi <d...@amc.dk> wrote:
Just for clarity, my concern was only that I'm now replacing the
original Element node with a new Text node, while I would have preferred
to replace the original Element node with another Element node if it was
possible.
It *is* possible, just not with a single method call. Remove the original
using remove() or removeChildren() and add another with element().
Supposing there's no other element inside the div:
element.removeChildren();
element.element("div").text("text");
What I get from Tapestry:
<div id="parent"> <div> I'm the OLD child Element </div> </div>
where both div-s are Element instances.
I wondered if it was possible to turn that into
<div id="parent"> <div> I'm the NEW child Element </div> </div>
Supposing "element" is the div with id="parent", this will do exactly what
you want:
element.removeChildren(); // result: <div id="parent"></div>
Element inner = element.element("div"); // result: <div
id="parent"><div></div></div>
inner.text("I'm the NEW child Element"); // result: <div
id="parent"><div>I'm the NEW child Element</div></div>
The last two lines could also be written as just
element.element("div").text("I'm the NEW child Element"); with the same
result.
You could also do this:
Element inner = element.find("div"); // returns the first child <div>
inner.removeChildren(); // clears its content
inner.text("I'm the NEW child Element");
Of course, this will only work when the outer <div> has an inner <div>,
while the solution above this one will work whatever the content inside
the outer <div>.
where both div-s are still Element instances,div as an Element instance
with different content. But if the new child div is a Text instead,
that's no problem, I just wanted to understand.
<div> is an HTML element and will *always* be represented by an Element
object in Tapestry DOM. <div> will never be a Text instance. You seem to
be confusing what element and text nodes are in HTML and, by consequence,
in Tapestry DOM.
--
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org