You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Steve Eynon <st...@googlemail.com> on 2011/06/06 07:34:08 UTC

Re: Rendering a Block

Hi,

An approach I've just used, is to render the XML into to the page,
convert the generated markup into a String and then remove the XML
from the DOM.

It may not be appropriate for all cases but it works if you just want
to template pure XML with no javascript or CSS.

Here's a component which renders it's body, passes the generated
markup to it's container as a String parameter and then removes itself
from the DOM:

import org.apache.tapestry5.MarkupWriter;
import org.apache.tapestry5.annotations.Parameter;
import org.apache.tapestry5.dom.Element;

public class RenderXml {

	@SuppressWarnings("unused")
	@Parameter(required=true)
	private String xml;
	
	void beforeRenderBody(MarkupWriter writer) {
		writer.element("div");
	}
	
	void afterRenderBody(MarkupWriter writer) {
		Element containingDiv = writer.getElement();
		writer.end();
		
		xml = containingDiv.getChildren().get(0).toString();		
		containingDiv.remove();
	}
}

The .tml is then just:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<t:container xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd"
xmlns:p="tapestry:parameter">
	<t:body />
</t:container>

It's usage .tml would then be:

	<t:renderXml t:xml="xml">
		your template xml here
		<t:blah/>
		your template xml here
	</t:renderXml>

	The rendered XML is : ${xml}

Unless anyone knows any different, I'm not seeing anything wrong with it.

Steve.

On 17 March 2011 05:11, Howard Lewis Ship <hl...@gmail.com> wrote:
> I've done work integrating Ext.GridPanel with Tapestry, but we've just
> let Ext render the data items on the client side.  I've actually had a
> lot of frustration because of the impedance mismatch between Ext (the
> server provides just data) and Tapestry (the server renders all
> content).
>

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