net.sf.tacos.ajax.components
Class AjaxFormSupportImpl

java.lang.Object
  extended by net.sf.tacos.ajax.components.AjaxFormSupportImpl
All Implemented Interfaces:
AjaxFormSupport, org.apache.tapestry.form.FormSupport, org.apache.tapestry.FormBehavior

public class AjaxFormSupportImpl
extends Object
implements AjaxFormSupport

Encapsulates most of the behavior of a Form component.

Since:
4.0
Author:
Howard M. Lewis Ship

Field Summary
protected  AjaxWebRequest ajaxRequest
           
static String FIELD_FOCUS_ATTRIBUTE
          Attribute set to true when a field has been focused; used to prevent conflicting JavaScript for field focusing from being emitted.
static String FORM_IDS
          Name of query parameter storing the ids alloocated while rendering the form, as a comma seperated list.
protected  org.apache.tapestry.IMarkupWriter hiddenWriter
           
static String RESERVED_FORM_IDS
          Names of additional ids that were pre-reserved, as a comma-sepereated list.
protected  ResponseBuilder response
           
static String SCRIPT
           
static String SUBMIT_MODE
          Indicates why the form was submitted: whether for normal ("submit"), refresh, or because the form was canceled.
 
Constructor Summary
AjaxFormSupportImpl(org.apache.tapestry.IMarkupWriter writer, org.apache.tapestry.IRequestCycle cycle, AjaxWebRequest ajaxRequest, org.apache.tapestry.IForm form)
          Creates a new rendering support instance.
 
Method Summary
 void addDeferredRunnable(Runnable runnable)
          
 void addEventHandler(org.apache.tapestry.form.FormEventType type, String functionName)
          Adds an event handler for the form, of the given type.
 void addHiddenValue(String name, String value)
          
 void addHiddenValue(String name, String id, String value)
          
protected  void emitEventHandlers(String formId)
           
protected  void emitEventManagerInitialization(String formId)
          Pre-renders the form, setting up some client-side form support.
 String getElementId(org.apache.tapestry.form.IFormComponent component)
          Constructs a unique identifier (within the Form).
 String getElementId(org.apache.tapestry.form.IFormComponent component, String baseId)
          Constructs a unique identifier (within the Form).
 String getEncodingType()
          If previously specified, the encoding type of this form
protected  org.apache.tapestry.IMarkupWriter getHiddenWriter()
          Gets the correct IMarkupWriter for this response render, depending on if this is a valid ajax request and the form contains components that were requested in render.
 boolean isRewinding()
          
 void prerenderField(org.apache.tapestry.IMarkupWriter writer, org.apache.tapestry.IComponent field, Location location)
          
 void registerForFocus(org.apache.tapestry.form.IFormComponent field, int priority)
          
 void render(String method, org.apache.tapestry.IRender informalParametersRenderer, org.apache.tapestry.engine.ILink link, String scheme)
          
 void render(String method, org.apache.tapestry.IRender informalParametersRenderer, org.apache.tapestry.engine.ILink link, String scheme, Integer port)
          
 String rewind()
          
 void setEncodingType(String encodingType)
          
protected  boolean shouldRender()
          Determines if script contributions should be rendered for the form.
 boolean wasPrerendered(org.apache.tapestry.IMarkupWriter writer, org.apache.tapestry.IComponent field)
          
protected  void writeHiddenField(org.apache.tapestry.IMarkupWriter writer, String name, String id, String value)
          Overwridden by org.apache.tapestry.wml.GoFormSupportImpl (WML).
protected  void writeHiddenFieldList()
          Writes out all hidden values previously added by addHiddenValue(String, String, String), plus the allocated id list.
protected  void writeHiddenFields()
          Writes out all hidden values previously added by addHiddenValue(String, String, String).
protected  void writeTag(org.apache.tapestry.IMarkupWriter writer, String method, String url)
          Writes the form action tag
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FORM_IDS

public static final String FORM_IDS
Name of query parameter storing the ids alloocated while rendering the form, as a comma seperated list. This information is used when the form is submitted, to ensure that the rewind allocates the exact same sequence of ids.

See Also:
Constant Field Values

RESERVED_FORM_IDS

public static final String RESERVED_FORM_IDS
Names of additional ids that were pre-reserved, as a comma-sepereated list. These are names beyond that standard set. Certain engine services include extra parameter values that must be accounted for, and page properties may be encoded as additional query parameters.

See Also:
Constant Field Values

SUBMIT_MODE

public static final String SUBMIT_MODE
Indicates why the form was submitted: whether for normal ("submit"), refresh, or because the form was canceled.

See Also:
Constant Field Values

SCRIPT

public static final String SCRIPT
See Also:
Constant Field Values

FIELD_FOCUS_ATTRIBUTE

public static final String FIELD_FOCUS_ATTRIBUTE
Attribute set to true when a field has been focused; used to prevent conflicting JavaScript for field focusing from being emitted.

See Also:
Constant Field Values

response

protected ResponseBuilder response

ajaxRequest

protected AjaxWebRequest ajaxRequest

hiddenWriter

protected org.apache.tapestry.IMarkupWriter hiddenWriter
Constructor Detail

AjaxFormSupportImpl

public AjaxFormSupportImpl(org.apache.tapestry.IMarkupWriter writer,
                           org.apache.tapestry.IRequestCycle cycle,
                           AjaxWebRequest ajaxRequest,
                           org.apache.tapestry.IForm form)
Creates a new rendering support instance.

Parameters:
writer -
cycle -
form -
Method Detail

addEventHandler

public void addEventHandler(org.apache.tapestry.form.FormEventType type,
                            String functionName)
Adds an event handler for the form, of the given type.

Specified by:
addEventHandler in interface org.apache.tapestry.FormBehavior

addHiddenValue

public void addHiddenValue(String name,
                           String value)

Specified by:
addHiddenValue in interface org.apache.tapestry.FormBehavior

addHiddenValue

public void addHiddenValue(String name,
                           String id,
                           String value)

Specified by:
addHiddenValue in interface org.apache.tapestry.FormBehavior

emitEventHandlers

protected void emitEventHandlers(String formId)
Parameters:
formId -

shouldRender

protected boolean shouldRender()
Determines if script contributions should be rendered for the form.

Returns:

getElementId

public String getElementId(org.apache.tapestry.form.IFormComponent component)
Constructs a unique identifier (within the Form). The identifier consists of the component's id, with an index number added to ensure uniqueness.

Simply invokes getElementId(org.apache.tapestry.form.IFormComponent, java.lang.String)with the component's id.

Specified by:
getElementId in interface org.apache.tapestry.FormBehavior

getElementId

public String getElementId(org.apache.tapestry.form.IFormComponent component,
                           String baseId)
Constructs a unique identifier (within the Form). The identifier consists of the component's id, with an index number added to ensure uniqueness.

Simply invokes getElementId(org.apache.tapestry.form.IFormComponent, java.lang.String)with the component's id.

Specified by:
getElementId in interface org.apache.tapestry.FormBehavior

isRewinding

public boolean isRewinding()

Specified by:
isRewinding in interface org.apache.tapestry.FormBehavior

render

public void render(String method,
                   org.apache.tapestry.IRender informalParametersRenderer,
                   org.apache.tapestry.engine.ILink link,
                   String scheme)

Specified by:
render in interface org.apache.tapestry.form.FormSupport

render

public void render(String method,
                   org.apache.tapestry.IRender informalParametersRenderer,
                   org.apache.tapestry.engine.ILink link,
                   String scheme,
                   Integer port)

Specified by:
render in interface org.apache.tapestry.form.FormSupport

emitEventManagerInitialization

protected void emitEventManagerInitialization(String formId)
Pre-renders the form, setting up some client-side form support. Returns the name of the client-side form event manager variable.


rewind

public String rewind()

Specified by:
rewind in interface org.apache.tapestry.form.FormSupport

setEncodingType

public void setEncodingType(String encodingType)

Specified by:
setEncodingType in interface org.apache.tapestry.FormBehavior

getEncodingType

public String getEncodingType()
If previously specified, the encoding type of this form

Specified by:
getEncodingType in interface AjaxFormSupport
Returns:
The encoding

writeHiddenField

protected void writeHiddenField(org.apache.tapestry.IMarkupWriter writer,
                                String name,
                                String id,
                                String value)
Overwridden by org.apache.tapestry.wml.GoFormSupportImpl (WML).


getHiddenWriter

protected org.apache.tapestry.IMarkupWriter getHiddenWriter()
Gets the correct IMarkupWriter for this response render, depending on if this is a valid ajax request and the form contains components that were requested in render.

Returns:

writeHiddenFields

protected void writeHiddenFields()
Writes out all hidden values previously added by addHiddenValue(String, String, String). Writes a <div> tag around writeHiddenFieldList(). Overriden by org.apache.tapestry.wml.GoFormSupportImpl.


writeHiddenFieldList

protected void writeHiddenFieldList()
Writes out all hidden values previously added by addHiddenValue(String, String, String), plus the allocated id list.


writeTag

protected void writeTag(org.apache.tapestry.IMarkupWriter writer,
                        String method,
                        String url)
Writes the form action tag

Parameters:
writer -
method -
url -

prerenderField

public void prerenderField(org.apache.tapestry.IMarkupWriter writer,
                           org.apache.tapestry.IComponent field,
                           Location location)

Specified by:
prerenderField in interface org.apache.tapestry.FormBehavior

wasPrerendered

public boolean wasPrerendered(org.apache.tapestry.IMarkupWriter writer,
                              org.apache.tapestry.IComponent field)

Specified by:
wasPrerendered in interface org.apache.tapestry.FormBehavior

addDeferredRunnable

public void addDeferredRunnable(Runnable runnable)

Specified by:
addDeferredRunnable in interface org.apache.tapestry.FormBehavior

registerForFocus

public void registerForFocus(org.apache.tapestry.form.IFormComponent field,
                             int priority)

Specified by:
registerForFocus in interface org.apache.tapestry.FormBehavior