You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Bill Holloway <bi...@peoplepad.com> on 2008/04/19 00:15:25 UTC

T5: Rendering a block via the DOM

I have a component that picks up a Block via
componentResources.getBlockParameter(String).  No problem.  But I need to
render this Block at the very bottom of the overall page, right before the
</body>.

Any thoughts?

-- 
Bill @ PeoplePad

Re: T5: Rendering a block via the DOM

Posted by Bill Holloway <bi...@peoplepad.com>.
Wow, Josh.  Thanks, that's a lot of work!  I'll try.

On Fri, Apr 18, 2008 at 6:53 PM, Josh Canfield <jo...@thedailytube.com>
wrote:

> I'm not sure if there is an easier way to do this, but you could
> configure a MarkupRendererFilter that finds and moves your elements
> before the page is written. This is how pageRenderSupport.addScript
> works, sortof...
>
> Here's something I whipped up. You could push something on the
> environment to store ids instead of adding an attribute. While I ran
> this, and it works, it's not guaranteed to be future proof, without
> bugs or the smartest way to do the task... enjoy!
>
> public void contributeMarkupRenderer(
>                OrderedConfiguration<MarkupRendererFilter> configuration) {
>        MarkupRendererFilter bodyMover = new MarkupRendererFilter() {
>                public void renderMarkup(MarkupWriter writer,
> MarkupRenderer renderer) {
>                        renderer.renderMarkup(writer);
>
>                        Document document = writer.getDocument();
>                        Element html = document.getRootElement();
>                        Element body = html.find("body");
>                        if (body == null) return; // no body no moving
>                        processNode(html, body);
>                }
>                private void processNode(Node node, Element body) {
>                        List<Node> children = node.getChildren();
>                        for (int i = 0; i < children.size(); ++i) {
>                                Node child = children.get(i);
>                                if (!(child instanceof Element))
>                                        continue;
>                                Element element = (Element) child;
>                                if
> (element.getAttribute("move-to-before-body") != null) {
>                                        children.remove(i);
>                                        body.getChildren().add(child);
>                                        --i; // one less element
>                                } else {
>                                        processNode(child, body);
>                                }
>                        }
>                }
>        };
>        configuration.add("bodyMover", bodyMover);
> }
>
> On Fri, Apr 18, 2008 at 3:15 PM, Bill Holloway <bi...@peoplepad.com> wrote:
> > I have a component that picks up a Block via
> > componentResources.getBlockParameter(String).  No problem.  But I need
> to
> > render this Block at the very bottom of the overall page, right before
> the
> > </body>.
> >
> > Any thoughts?
> >
> > --
> > Bill @ PeoplePad
> >
>
>
>
> --
> --
> TheDailyTube.com. Sign up and get the best new videos on the internet
> delivered fresh to your inbox.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Bill @ PeoplePad

Re: T5: Rendering a block via the DOM

Posted by Josh Canfield <jo...@thedailytube.com>.
I'm not sure if there is an easier way to do this, but you could
configure a MarkupRendererFilter that finds and moves your elements
before the page is written. This is how pageRenderSupport.addScript
works, sortof...

Here's something I whipped up. You could push something on the
environment to store ids instead of adding an attribute. While I ran
this, and it works, it's not guaranteed to be future proof, without
bugs or the smartest way to do the task... enjoy!

public void contributeMarkupRenderer(
		OrderedConfiguration<MarkupRendererFilter> configuration) {
	MarkupRendererFilter bodyMover = new MarkupRendererFilter() {
		public void renderMarkup(MarkupWriter writer, MarkupRenderer renderer) {
			renderer.renderMarkup(writer);
		
			Document document = writer.getDocument();
			Element html = document.getRootElement();
			Element body = html.find("body");
			if (body == null) return; // no body no moving
			processNode(html, body);
		}
		private void processNode(Node node, Element body) {
			List<Node> children = node.getChildren();
			for (int i = 0; i < children.size(); ++i) {
				Node child = children.get(i);
				if (!(child instanceof Element))
					continue;
				Element element = (Element) child;
				if (element.getAttribute("move-to-before-body") != null) {
					children.remove(i);
					body.getChildren().add(child);
					--i; // one less element
				} else {
					processNode(child, body);
				}
			}
		}
	};
	configuration.add("bodyMover", bodyMover);
}

On Fri, Apr 18, 2008 at 3:15 PM, Bill Holloway <bi...@peoplepad.com> wrote:
> I have a component that picks up a Block via
> componentResources.getBlockParameter(String).  No problem.  But I need to
> render this Block at the very bottom of the overall page, right before the
> </body>.
>
> Any thoughts?
>
> --
> Bill @ PeoplePad
>



-- 
--
TheDailyTube.com. Sign up and get the best new videos on the internet
delivered fresh to your inbox.

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