org.apache.tapestry.html
Class Body

java.lang.Object
  extended by org.apache.tapestry.spec.BaseLocatable
      extended by org.apache.tapestry.AbstractComponent
          extended by org.apache.tapestry.html.Body
All Implemented Interfaces:
IComponent, ILocatable, ILocationHolder, IRender, IScriptProcessor

public abstract class Body
extends AbstractComponent
implements IScriptProcessor

The body of a Tapestry page. This is used since it allows components on the page access to an initialization script (that is written the start, just inside the <body> tag). This is currently used by Rollover and Script components. [Component Reference]

Version:
$Id: Body.java 244170 2005-03-17 08:54:30Z pferraro $
Author:
Howard Lewis Ship

Constructor Summary
Body()
           
 
Method Summary
 void addBodyScript(String script)
          Adds additional scripting code to the page.
 void addExternalScript(IResourceLocation scriptLocation)
          Used to include a script from an outside URL (the scriptLocation is a URL, probably obtained from an asset.
 void addInitializationScript(String script)
          Adds other initialization, in the form of additional JavaScript code to execute from the <body>'s onLoad event handler.
protected  void cleanupAfterRender(IRequestCycle cycle)
          Invoked by AbstractComponent.render(IMarkupWriter, IRequestCycle) after the component renders, to clear any parameters back to null (or 0, or false, or whatever the correct default is).
protected  void finishLoad()
          Sets the element parameter property to its default, "body".
static Body get(IRequestCycle cycle)
          Retrieves the Body that was stored into the request cycle.
abstract  String getElement()
           
 String getPreloadedImageReference(String URL)
          Adds to the script an initialization for the named variable as an Image(), to the given URL.
 String getUniqueString(String baseValue)
          Ensures that the given string is unique.
protected  void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
          Invoked by AbstractComponent.render(IMarkupWriter, IRequestCycle) to actually render the component (with any parameter values already set).
abstract  void setElement(String element)
           
protected  void writeScript(IMarkupWriter writer)
          Writes a single large JavaScript block containing: Any image initializations Any scripting Any initializations
 
Methods inherited from class org.apache.tapestry.AbstractComponent
addAsset, addBody, addComponent, finishLoad, fireObservedChange, fireObservedChange, fireObservedChange, fireObservedChange, fireObservedChange, fireObservedChange, fireObservedChange, fireObservedChange, fireObservedChange, format, format, format, format, formatString, formatString, formatString, formatString, generateAttributes, getAsset, getAssets, getBeans, getBinding, getBindingNames, getBindings, getBody, getBodyCount, getChangeObserver, getComponent, getComponents, getContainer, getExtendedId, getId, getIdPath, getListeners, getMessage, getMessages, getNamespace, getPage, getProperty, getSpecification, getString, pageEndRender, prepareForRender, render, renderBody, renderInformalParameters, setBinding, setContainer, setId, setNamespace, setPage, setProperty, setSpecification, toString
 
Methods inherited from class org.apache.tapestry.spec.BaseLocatable
getLocation, setLocation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.tapestry.ILocationHolder
setLocation
 
Methods inherited from interface org.apache.tapestry.ILocatable
getLocation
 

Constructor Detail

Body

public Body()
Method Detail

getPreloadedImageReference

public String getPreloadedImageReference(String URL)
Adds to the script an initialization for the named variable as an Image(), to the given URL.

Returns a reference, a string that can be used to represent the preloaded image in a JavaScript function.

Since:
1.0.2

addInitializationScript

public void addInitializationScript(String script)
Adds other initialization, in the form of additional JavaScript code to execute from the <body>'s onLoad event handler. The caller is responsible for adding a semicolon (statement terminator). This method will add a newline after the script.

Specified by:
addInitializationScript in interface IScriptProcessor

addBodyScript

public void addBodyScript(String script)
Adds additional scripting code to the page. This code will be added to a large block of scripting code at the top of the page (i.e., the before the <body> tag).

This is typically used to add some form of JavaScript event handler to a page. For example, the Rollover component makes use of this.

Another way this is invoked is by using the Script component.

The string will be added, as-is, within the <script> block generated by this Body component. The script should not contain HTML comments, those will be supplied by this Body component.

A frequent use is to add an initialization function using this method, then cause it to be executed using addInitializationScript(String).

Specified by:
addBodyScript in interface IScriptProcessor

addExternalScript

public void addExternalScript(IResourceLocation scriptLocation)
Used to include a script from an outside URL (the scriptLocation is a URL, probably obtained from an asset. This adds an <script src="..."> tag before the main <script> tag. The Body component ensures that each URL is included only once.

Specified by:
addExternalScript in interface IScriptProcessor
Since:
1.0.5

get

public static Body get(IRequestCycle cycle)
Retrieves the Body that was stored into the request cycle. This allows components wrapped by the Body to locate it and access the services it provides.


renderComponent

protected void renderComponent(IMarkupWriter writer,
                               IRequestCycle cycle)
Description copied from class: AbstractComponent
Invoked by AbstractComponent.render(IMarkupWriter, IRequestCycle) to actually render the component (with any parameter values already set). This is the method that subclasses must implement.

Specified by:
renderComponent in class AbstractComponent

cleanupAfterRender

protected void cleanupAfterRender(IRequestCycle cycle)
Description copied from class: AbstractComponent
Invoked by AbstractComponent.render(IMarkupWriter, IRequestCycle) after the component renders, to clear any parameters back to null (or 0, or false, or whatever the correct default is). Primarily, this is used to ensure that the component doesn't hold onto any objects that could otherwise be garbage collected.

Subclasses may override this implementation, but must also invoke it.

Overrides:
cleanupAfterRender in class AbstractComponent

writeScript

protected void writeScript(IMarkupWriter writer)
Writes a single large JavaScript block containing:

The script is written into a nested markup writer.

If there are any other initializations (see addInitializationScript(String)), then a function to execute them is created.


getElement

public abstract String getElement()

setElement

public abstract void setElement(String element)

finishLoad

protected void finishLoad()
Sets the element parameter property to its default, "body".

Overrides:
finishLoad in class AbstractComponent
Since:
3.0

getUniqueString

public String getUniqueString(String baseValue)
Description copied from interface: IScriptProcessor
Ensures that the given string is unique. The string is either returned unchanged, or a suffix is appended to ensure uniqueness.

Specified by:
getUniqueString in interface IScriptProcessor
Since:
3.0