net.sf.tacos.ajax.contrib
Class RicoResponseBuilder

java.lang.Object
  extended bynet.sf.tacos.ajax.contrib.RicoResponseBuilder
All Implemented Interfaces:
ResponseBuilder

public class RicoResponseBuilder
extends Object
implements ResponseBuilder

Handles logic of directly invoking and rendering component responses to ajax request.

As per the rico documentation, will try to write a response xml document back to the supplied IMarkupWriter looking somewhat like:

 
 
 
Mr. Pat Barnes1743 1st Avenue Boston, Boston 71204-2345Executive Vice PresidentPhone #: (972) 555-0293Mobile #: (972) 555-0295Notes: Spouse playes tennis at the country club with John.

Project page: http://openrico.org

Author:
jkuhnert

Field Summary
protected  AjaxWebRequest ajaxRequest
          Ajax request
static String CONTENT_TYPE
          Content type
protected  IMarkupWriter writer
          XML Markup writer to write to
protected  Map writers
          Map of component id's to their nested markup writer instances, which we have to use or else the writer will conflic with our xml nodes
 
Constructor Summary
RicoResponseBuilder()
          Default constructor
 
Method Summary
protected  IComponent checkComponentContainers(IComponent comp)
          Certain components that a requested component refresh are contained by might prevent the successfull render of a component directly, such as a Foreach component.
 void cleanupAfterRender()
          Invoked by AjaxDirectService after a request cycle so invokers can cleanup resources.

In the case of full page/non direct component invocations this causes all the buffered component IMarkupWriter instances to have their contents written to the response stream.

 AjaxWebRequest getAjaxRequest()
          The ajax request
protected  IMarkupWriter getComponentWriter(String id)
          Gets a NestedMarkupWriter for the specified component to write to and caches the buffer for later write to the stream via the cleanupAfterRender().
 String getContentType()
          Should return the content type response that this builder generates. Ie "text/plain" or "text/xml". These content types must also exist in the hivemodule.xml contribution tapestry.markup.MarkupFilters.
 IMarkupWriter getWriter()
          The writer
 IMarkupWriter getWriter(IComponent component, IRequestCycle cycle, IMarkupWriter cwriter)
          Invoked by enhanced IRender.render(org.apache.tapestry.IMarkupWriter, org.apache.tapestry.IRequestCycle) methods before rendering to replace their incoming IMarkupWriter instance with the one provided by this class, which may return the same writer or a special writer depending on the circumstances.
 void prepareForRender()
          Called before invoking either ResponseBuilder.updateComponentsDirect(IRequestCycle, IPage, IPage, IComponent), or if in full render mode invoking renderRequest(
 void renderResponse(IRequestCycle cycle, IPage activePage, IPage componentPage, IComponent component)
          Called to render a complete response to the client, in the case of of direct component updates being set to false.
 void setAjaxRequest(AjaxWebRequest ajaxRequest)
          Sets the associated ajax request.
 void setWriter(IMarkupWriter writer)
          Sets the text/xml response writer.
 void updateComponentsDirect(IRequestCycle cycle, IPage activePage, IPage componentPage, IComponent component)
          Called to update all components in cycle directly, without causing any other component to render output.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONTENT_TYPE

public static final String CONTENT_TYPE
Content type

See Also:
Constant Field Values

ajaxRequest

protected AjaxWebRequest ajaxRequest
Ajax request


writer

protected IMarkupWriter writer
XML Markup writer to write to


writers

protected Map writers
Map of component id's to their nested markup writer instances, which we have to use or else the writer will conflic with our xml nodes

Constructor Detail

RicoResponseBuilder

public RicoResponseBuilder()
Default constructor

Method Detail

getWriter

public IMarkupWriter getWriter(IComponent component,
                               IRequestCycle cycle,
                               IMarkupWriter cwriter)
Invoked by enhanced IRender.render(org.apache.tapestry.IMarkupWriter, org.apache.tapestry.IRequestCycle) methods before rendering to replace their incoming IMarkupWriter instance with the one provided by this class, which may return the same writer or a special writer depending on the circumstances.

Specified by:
getWriter in interface ResponseBuilder
Parameters:
component -
cycle -
cwriter - Current writer rendering response
Returns:
A valid IMarkupWriter, which may be a NullMarkupWriter, an ajax xml response stream, or a normal html response stream.

updateComponentsDirect

public void updateComponentsDirect(IRequestCycle cycle,
                                   IPage activePage,
                                   IPage componentPage,
                                   IComponent component)
Called to update all components in cycle directly, without causing any other component to render output.

Specified by:
updateComponentsDirect in interface ResponseBuilder
Parameters:
cycle -
activePage -
componentPage -
component -

checkComponentContainers

protected IComponent checkComponentContainers(IComponent comp)
Certain components that a requested component refresh are contained by might prevent the successfull render of a component directly, such as a Foreach component. This method checks all of the components in a page to see if the specified component has a container of one of these types.

Parameters:
comp - The IComponent to check containers of
Returns:
The most logical topmost IComponent that should be rendered before this component may be rendered.

prepareForRender

public void prepareForRender()
Called before invoking either ResponseBuilder.updateComponentsDirect(IRequestCycle, IPage, IPage, IComponent), or if in full render mode invoking renderRequest(

Specified by:
prepareForRender in interface ResponseBuilder

renderResponse

public void renderResponse(IRequestCycle cycle,
                           IPage activePage,
                           IPage componentPage,
                           IComponent component)
Called to render a complete response to the client, in the case of of direct component updates being set to false.

Specified by:
renderResponse in interface ResponseBuilder
Parameters:
cycle -
activePage -
componentPage -
component -

cleanupAfterRender

public void cleanupAfterRender()
Invoked by AjaxDirectService after a request cycle so invokers can cleanup resources.

In the case of full page/non direct component invocations this causes all the buffered component IMarkupWriter instances to have their contents written to the response stream.

Specified by:
cleanupAfterRender in interface ResponseBuilder

getComponentWriter

protected IMarkupWriter getComponentWriter(String id)
Gets a NestedMarkupWriter for the specified component to write to and caches the buffer for later write to the stream via the cleanupAfterRender().

Parameters:
id -
Returns:
Writer component will write to.

getAjaxRequest

public AjaxWebRequest getAjaxRequest()
The ajax request

Specified by:
getAjaxRequest in interface ResponseBuilder
Returns:

setAjaxRequest

public void setAjaxRequest(AjaxWebRequest ajaxRequest)
Sets the associated ajax request.

Specified by:
setAjaxRequest in interface ResponseBuilder
Parameters:
ajaxRequest -

getWriter

public IMarkupWriter getWriter()
The writer

Specified by:
getWriter in interface ResponseBuilder
Returns:

setWriter

public void setWriter(IMarkupWriter writer)
Sets the text/xml response writer.

Specified by:
setWriter in interface ResponseBuilder
Parameters:
writer -

getContentType

public String getContentType()
Should return the content type response that this builder generates. Ie "text/plain" or "text/xml". These content types must also exist in the hivemodule.xml contribution tapestry.markup.MarkupFilters.

Specified by:
getContentType in interface ResponseBuilder
Returns:
A valid content type required by this builder.