Martin,
I've just looked at DocumentScriptBuilder, which seems to be a delegate
of PageRenderSupport(Impl). I understand that PageRenderSupport uses a
notification (cleanup i think) to know when to insert the scripts, but
the way scripts are added (correct me if I'm wrong) are via explicit
method calls as opposed to a declarative way. While this could work I'd
prefer to just use implicit components in the template, and when the
page is rendered, have a the component or another service handle
appending to the <head>. Here's a test component method that I've hacked
out that does the basics. Right now it just inserts a bogus link tag:
@BeginRender
void beginRender(MarkupWriter writer) {
Element eHead = writer.getDocument().find("html/head");
eHead.element("link", "rel", "stylesheet", "type", "text/css",
"href", "test.css");
}
I'm not sure how I feel about this. Obviously it doesn't address
ordering, but it seems to be 'correct' other than that and the fact that
I can't figure out how to close the <link> element (writer.end() throws
exceptions). You seem to favor a service over a component - do mind
explaining why?
Also, could you elaborate on 'peek' ing? I'm still new to Tapestry and
I'm not completely aware of all the terms/architecture yet.
Thanks tons for your input.
chris
Martin Reurings wrote:
Well, one could peek to get the markupwriter, but perhaps you may want
to dig through the sourcecode to see what Howard's done to support
adding javascript files on the fly. He uses a 'service'
DocumentScriptBuilder to 'declare' the various scripts as well as keep
them unique and then once all components have rendered he modifies the
DOM to prepend script tags to the body.
I've been meaning to build a style version for a project we're doing
but just haven't found the time yet (it's not a critical issue as yet).
The idea here would be:
1) create a 'service' to declare your stylesheets to. In essence any
List<String> that ensures unique entries and if desires order.
2) declare this service in your AppModule in such a way that it's
available to all pages
3) Using peek or peekrequired any component can declare stylesheets to
the service
4) On document cleanup add a link for each declared stylesheet to the
end of head-elememt (preserving order).
I don't have the details of where to do step (4) yet, I haven't had
the need to find out but if you follow the trail of breadcrumbs and
hunt down DocumentScriptBuilder one would assume you'd be able to do
this :)
Other than this alternative, I see nothing wrong with what you
proposed, except perhaps that it doesn't ensure uniqueness, which I
would find essential :)
Good luck,
Martin
Chris Lewis wrote:
So it looks like one would need to (re)create something similar to
the T4 Shell component.
I've taken a brief look at the DOM api, and if I were to write
something as focused as a Style component, then it looks like I'd
have to:
1) create my component class, either in my.namespace.components, or
another module that is loaded and contributed
2) get a MarkupWriter instance via void beginRender/@BeginRender
3) use writer.getRootElement() to get the root, and then traverse
into the <head>
4) assuming eHead is my <head> Element, use eHead.element("link",
"rel", "stylesheet", "type", "text/css", "href",
"TODO-css-url-here"), to append a <link>
Can anyone comment on the (in)correctness of this?
It'd be nice to ensure ordering of the sheets somehow, so they can
cascade properly. It'd be easier to do that with a more sophisticated
Shell-link component that handled building the page base (head,
metas, scripts, etc). Anyway, please share thoughts.
thanks
chris
Robert Zeigler wrote:
T5 renders with a dom.
Gives you a lot of control...
You could create a "style" component that finds the head and inserts
the appropriate <link> element.
Then your components could add their own stylesheets using the style
component, with the page and containing components none the wiser.
You would want to make sure that a given stylesheet is inserted only
once, of course (eg, if your component is contained within a loop...).
A component like this should be very straightforward to write in T5.
Robert
On Aug 13, 2007, at 8/134:51 PM , Chris Lewis wrote:
One of the nice things I learned in my brief investigation of
T4.1.2 was that the Shell component would automatically pick up any
style sheets a page declared using the @Style annotation (or
something like that). I've been wondering how something like this
might be achieved in T5, using the available components as opposed
to subclassing a base page. This seems like a feature that would be
part of the core, as it is such a common need.
I know I could emulate this by creating a layout that expected a
page property, say externalCss (a collection), and using the Loop
component to iterate it and insert the link elements. Is this the
only way to do this in T5?
thanks!
chris
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]