wicket
Class AjaxHandler

java.lang.Object
  extended bywicket.AjaxHandler
All Implemented Interfaces:
IBodyOnloadContributor, IHeaderContributor, java.io.Serializable

public abstract class AjaxHandler
extends java.lang.Object
implements java.io.Serializable, IHeaderContributor, IBodyOnloadContributor

Abstract class for handling Ajax roundtrips. This class serves as a base for javascript specific implementations, like ones based on Dojo or Scriptaculous.

Author:
Eelco Hillenius
See Also:
Serialized Form

Field Summary
protected  IResourceStream resourceStream
          The actual raw resource this class is rendering
 
Constructor Summary
AjaxHandler()
          Construct.
 
Method Summary
protected  void addJsReference(HtmlHeaderContainer container, PackageResourceReference ref)
          Convenience method to add a javascript reference.
(package private)  void bind(Component hostComponent)
          Bind this handler to the given component.
protected  void configure(Response response, IResourceStream resourceStream)
          Configures the response, default by setting the content type and length.
 java.lang.String getBodyOnload()
          Gets the onload statement(s) for the body component.
protected  java.lang.String getBodyOnloadContribution()
          Gets the onload statement(s) for the body component.
protected  java.lang.String getBodyOnloadInitContribution()
          One time (per page) body onload contribution that is the same for all ajax variant implementations (e.g.
 java.lang.String getCallbackUrl()
          Gets the url that references this handler.
protected  Component getComponent()
          Gets the component that this handler is bound to.
protected abstract  java.lang.String getImplementationId()
          Gets the unique id of an ajax implementation.
protected abstract  IResourceStream getResponse()
          Gets the response to render to the requester.
protected  java.lang.String getResponseType()
          Gets the response type mime, e.g.
(package private)  void internalOnComponentRendered()
          Called to indicate that the component that has this handler registered has been rendered.
protected  void onBind()
          Called when the component was bound to it's host component.
protected  void onComponentRendered()
          Called to indicate that the component that has this handler registered has been rendered.
 void onComponentTag(ComponentTag tag)
          Called any time a component that has this handler registered is rendering the component tag.
(package private)  void onRequest()
          Called when an Ajax request is to be handled.
 void renderHead(HtmlHeaderContainer container)
          Render to the web response whatever the component wants to contribute to the head section.
protected  void renderHeadContribution(HtmlHeaderContainer container)
          Let this handler print out the needed header contributions.
protected  void renderHeadInitContribution(HtmlHeaderContainer container)
          Do a one time (per page) header contribution that is the same for all ajax variant implementations (e.g.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

resourceStream

protected IResourceStream resourceStream
The actual raw resource this class is rendering

Constructor Detail

AjaxHandler

public AjaxHandler()
Construct.

Method Detail

getBodyOnload

public final java.lang.String getBodyOnload()
Description copied from interface: IBodyOnloadContributor
Gets the onload statement(s) for the body component.

Specified by:
getBodyOnload in interface IBodyOnloadContributor
Returns:
the onload statement(s) for the body component
See Also:
IBodyOnloadContributor.getBodyOnload()

renderHead

public final void renderHead(HtmlHeaderContainer container)
Description copied from interface: IHeaderContributor
Render to the web response whatever the component wants to contribute to the head section.

Note: This method is kind of dangerous as users are able to write to the output whatever they like.

Specified by:
renderHead in interface IHeaderContributor
Parameters:
container - The HtmlHeaderContainer
See Also:
IHeaderContributor.renderHead(wicket.markup.html.HtmlHeaderContainer)

onComponentTag

public void onComponentTag(ComponentTag tag)
Called any time a component that has this handler registered is rendering the component tag. Use this method e.g. to bind to javascript event handlers of the tag

Parameters:
tag - the tag that is rendered

getCallbackUrl

public final java.lang.String getCallbackUrl()
Gets the url that references this handler.

Returns:
the url that references this handler

getImplementationId

protected abstract java.lang.String getImplementationId()
Gets the unique id of an ajax implementation. This should be implemented by base classes only - like the dojo or scriptaculous implementation - to provide a means to differentiate between implementations while not going to the level of concrete implementations. It is used to ensure 'static' header contributions are done only once per implementation.

Returns:
unique id of an ajax implementation

getResponse

protected abstract IResourceStream getResponse()
Gets the response to render to the requester.

Returns:
the response to render to the requester

renderHeadInitContribution

protected void renderHeadInitContribution(HtmlHeaderContainer container)
Do a one time (per page) header contribution that is the same for all ajax variant implementations (e.g. Dojo, Scriptaculous). This implementation does nothing.

Parameters:
container - head container

renderHeadContribution

protected void renderHeadContribution(HtmlHeaderContainer container)
Let this handler print out the needed header contributions. This implementation does nothing.

Parameters:
container - head container

getComponent

protected final Component getComponent()
Gets the component that this handler is bound to.

Returns:
the component that this handler is bound to

onBind

protected void onBind()
Called when the component was bound to it's host component. You can get the bound host component by calling getComponent.


getBodyOnloadInitContribution

protected java.lang.String getBodyOnloadInitContribution()
One time (per page) body onload contribution that is the same for all ajax variant implementations (e.g. Dojo, Rico, Qooxdoo).

Returns:
the onload statement(s) for the body component

getBodyOnloadContribution

protected java.lang.String getBodyOnloadContribution()
Gets the onload statement(s) for the body component. Override this method to provide custom contributions.

Returns:
the onload statement(s) for the body component

onComponentRendered

protected void onComponentRendered()
Called to indicate that the component that has this handler registered has been rendered. Use this method to do any cleaning up of temporary state


configure

protected void configure(Response response,
                         IResourceStream resourceStream)
Configures the response, default by setting the content type and length.

Parameters:
response - the response
resourceStream - the resource stream that will be rendered

getResponseType

protected java.lang.String getResponseType()
Gets the response type mime, e.g. 'text/html' or 'text/javascript'.

Returns:
the response type mime

addJsReference

protected void addJsReference(HtmlHeaderContainer container,
                              PackageResourceReference ref)
Convenience method to add a javascript reference.

Parameters:
container - the header container
ref - reference to add

bind

final void bind(Component hostComponent)
Bind this handler to the given component.

Parameters:
hostComponent - the component to bind to

internalOnComponentRendered

final void internalOnComponentRendered()
Called to indicate that the component that has this handler registered has been rendered. Use this method to do any cleaning up of temporary state.


onRequest

final void onRequest()
Called when an Ajax request is to be handled.



Copyright © 2004-2006 Wicket developers. All Rights Reserved.