Dear Wiki user, You have subscribed to a wiki page or wiki category on "Jakarta-tapestry Wiki" for change notification.
The following page has been changed by JesseKuhnert: http://wiki.apache.org/jakarta-tapestry/41RenderCycleDesign ------------------------------------------------------------------------------ </xml> }}} + ==== What's happening on the server? ==== + In it's most basic form, tapestry as a whole generally does the following. + * Takes an incoming HttpServletRequest and sets up all of the core tapestry infrastructure, such as hivemind injectable objects for WebRequest/etc. + * Looks at the parameters for the incoming request, ie "&service=direct" to determine which service should handle the request. In this case we want the DirectService, which is more or less the staple of most system requests. + * The direct service reads in the request parameters and invokes the "listener" that was specified in the request, once that listeners method has been invoked it then hands off the response to the ResponseRenderer service. + * The ResponseRenderer sets up the actual IMarkupWriter which is tied to the OutputStream being written back to the client browser (in most cases). + * Once the IMarkupWriter is setup all request flow is handed off to the IRequestCycle object via IRequestCycle.renderPage(IPage page); (I left out the part about pages, but suffice it to say that the DirectService is able to determine which page a particular response should go to and sets it up accordingly ) + * The Page object, which probably in 90% of cases is an AbstractPage instance then starts to render itself. This rendering is where ajax requests start to break down. + + What we see with Page/Component rendering is a container/child sort of rendering model, where nothing can be known about a particular containers children save by the container itself. So, rendering is handled by components directly. Via a combination of IRender.render() IComponent.renderComponent(writer, request) the chain flows down and down through all of the contained components until the entire response is written. + + The problem with this for ajax is that we don't want all the components to render. We only want one, or maybe two or three or whatever. Replacing the IMarkupWriter instance with one of your own doesn't do it because the IMarkupWriter is dumb in that it only knows how to write textual data back, it doesn't know or care whether its currently rendering component A or component Z. It writes whatever markup it's told and that's it. + + The tacos solution to this problem was to sort of "hot swap" IMarkupWriters in the rendering chain, depending on whether a component was requested to have it's content renderd by the client. This was achieved by creating two markup writers for every request. One NullMarkupWriter, which when used throws out all of the content that is written to it, and another valid IMarkupWriter that is used to write valid content to the client. The only problem left was how to switch out the correct writer depending on the component being rendered? + + The solution was to use javassist to extend "every" component in the system, whether it is tapestrys compnoent or your own custom component via subclassing any object that .isAssignableFrom(AbstractComponent.class). The renderComponent() method was enhanced to look something like this: + + {{{ + // The writer being passed in here is a NullMarkupWriter by default in ajax responses + public void renderComponent(IMarkupWriter writer, IRequestCycle cycle) + { + if (!ajaxRequest.isValidRequest()) + super.renderComponent(writer, cycle); + + if (ajaxRequest.componentWasRequestedToRefresh(this)) + super.renderComponent(ajaxRequest.getAjaxWriter(), cycle); + } + }}} + + That's about as magical as it gets. There are a lot of gotchas when it comes to javascript that we will get to shortly, but that's the magic that happens in tacos more or less. + --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
