com.primix.tapestry.valid
Class AbstractValidatingTextField

java.lang.Object
  |
  +--com.primix.tapestry.AbstractComponent
        |
        +--com.primix.tapestry.form.AbstractFormComponent
              |
              +--com.primix.tapestry.form.AbstractTextField
                    |
                    +--com.primix.tapestry.valid.AbstractValidatingTextField
All Implemented Interfaces:
java.util.EventListener, IComponent, IFormComponent, IRender, IValidatingTextField, PageDetachListener
Direct Known Subclasses:
DateField, IntegerField, NumericField, ValidatingTextField

public abstract class AbstractValidatingTextField
extends AbstractTextField
implements IValidatingTextField, IFormComponent, PageDetachListener

Base class for several classes that validate their input from the user.

All subclasses share the following features:

Version:
$Id: AbstractValidatingTextField.java,v 1.14 2001/09/10 18:25:14 hship Exp $
Author:
Howard Ship

Fields inherited from class com.primix.tapestry.AbstractComponent
id, page, specification, wrapped, wrappedCount
 
Constructor Summary
AbstractValidatingTextField()
           
 
Method Summary
protected  void beforeCloseTag(IResponseWriter writer, IRequestCycle cycle)
          Invokes IValidationDelegate.writeAttributes(IValidatingTextField,IResponseWriter,IRequestCycle).
protected  void finishLoad()
          Registers this component as a PageDetachListener.
 IValidationDelegate getDelegate()
          Returns the component's delegate, or throws RequiredParameterException.
 IBinding getDelegateBinding()
           
 java.lang.String getDisplayName()
          Returns the display name for the component, suitable for display to a user.
 IBinding getDisplayNameBinding()
           
 boolean getError()
          Returns true if there was a validation error.
 IBinding getRequiredBinding()
           
protected  java.lang.String getString(java.lang.String key, java.lang.Object argument)
           
protected  java.lang.String getString(java.lang.String key, java.lang.Object[] arguments)
          Gets and formats a localized string from the com.primix.tapestry.valid.ValidationStrings property bundle.
protected  java.lang.String getString(java.lang.String key, java.lang.Object arg1, java.lang.Object arg2)
           
 boolean isRequired()
          Returns the value of the required parameter, or false if the parameter is not bound.
protected  void notifyDelegate(ValidationConstraint constraint, java.lang.String defaultErrorMessage)
          Invoked (from update(String), usually} to indicate an error converting from the submitted text value to the appropriate data value.
 void pageDetached(PageEvent event)
          Clear the error, text and delegate properties at the end of request cycle.
protected abstract  java.lang.String read()
          Invoked by readValue() to read the underlying data value (in a way specific to the subclass implementation) and convert it to a String.
protected  java.lang.String readValue()
          Invoked by render(IResponseWriter writer, IRequestCycle cycle) when rendering a response.
 void refresh()
          Forces the component to re-read through its text binding.
 void render(IResponseWriter writer, IRequestCycle cycle)
          Renders the component, which involves the delegate.
 void setDelegateBinding(IBinding value)
           
 void setDisplayNameBinding(IBinding value)
           
 void setError(boolean value)
          Allows the error state to be set externally.
 void setRequiredBinding(IBinding value)
           
protected abstract  void update(java.lang.String value)
          Invoked from updateValue(String) to validate that the new value (submitted in the form by the user) conforms to the rules for this component.
protected  void updateValue(java.lang.String value)
          Invoked by render(IResponseWriter writer, IRequestCycle cycle) when a value is obtained from the HttpServletRequest.
 
Methods inherited from class com.primix.tapestry.form.AbstractTextField
getDisabledBinding, getDisplayWidthBinding, getHiddenBinding, getMaximumLengthBinding, getName, setDisabledBinding, setDisplayWidthBinding, setHiddenBinding, setMaximumLengthBinding
 
Methods inherited from class com.primix.tapestry.form.AbstractFormComponent
getForm, getForm
 
Methods inherited from class com.primix.tapestry.AbstractComponent
addAsset, addComponent, addWrapped, cleanupAfterRender, cleanupComponent, finishLoad, fireObservedChange, fireObservedChange, fireObservedChange, fireObservedChange, fireObservedChange, fireObservedChange, fireObservedChange, fireObservedChange, fireObservedChange, fireObservedChange, generateAttributes, getAsset, getAssets, getBeans, getBinding, getBindingNames, getBindings, getChangeObserver, getComponent, getComponents, getContainer, getExtendedId, getId, getIdPath, getListeners, getPage, getSpecification, prepareForRender, renderWrapped, reset, setBinding, setContainer, setId, setPage, setSpecification, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.primix.tapestry.valid.IValidatingTextField
getName
 
Methods inherited from interface com.primix.tapestry.IComponent
addAsset, addComponent, addWrapped, finishLoad, getAsset, getAssets, getBinding, getBindingNames, getBindings, getComponent, getComponents, getContainer, getExtendedId, getId, getIdPath, getPage, getSpecification, renderWrapped, setBinding, setContainer, setId, setPage, setSpecification
 
Methods inherited from interface com.primix.tapestry.form.IFormComponent
getForm, getName
 

Constructor Detail

AbstractValidatingTextField

public AbstractValidatingTextField()
Method Detail

finishLoad

protected void finishLoad()
Registers this component as a PageDetachListener.
Overrides:
finishLoad in class AbstractComponent
Since:
1.0.5

getString

protected java.lang.String getString(java.lang.String key,
                                     java.lang.Object[] arguments)
Gets and formats a localized string from the com.primix.tapestry.valid.ValidationStrings property bundle.

getString

protected java.lang.String getString(java.lang.String key,
                                     java.lang.Object argument)

getString

protected java.lang.String getString(java.lang.String key,
                                     java.lang.Object arg1,
                                     java.lang.Object arg2)

getDisplayNameBinding

public IBinding getDisplayNameBinding()

setDisplayNameBinding

public void setDisplayNameBinding(IBinding value)

getDisplayName

public java.lang.String getDisplayName()
Description copied from interface: IValidatingTextField
Returns the display name for the component, suitable for display to a user.
Specified by:
getDisplayName in interface IValidatingTextField

getDelegateBinding

public IBinding getDelegateBinding()

setDelegateBinding

public void setDelegateBinding(IBinding value)

getDelegate

public IValidationDelegate getDelegate()
Returns the component's delegate, or throws RequiredParameterException.

readValue

protected java.lang.String readValue()
Description copied from class: AbstractTextField
Invoked by AbstractTextField.render(IResponseWriter writer, IRequestCycle cycle) when rendering a response.
Overrides:
readValue in class AbstractTextField

read

protected abstract java.lang.String read()
Invoked by readValue() to read the underlying data value (in a way specific to the subclass implementation) and convert it to a String.

updateValue

protected void updateValue(java.lang.String value)
Description copied from class: AbstractTextField
Invoked by AbstractTextField.render(IResponseWriter writer, IRequestCycle cycle) when a value is obtained from the HttpServletRequest.
Overrides:
updateValue in class AbstractTextField

update

protected abstract void update(java.lang.String value)
Invoked from updateValue(String) to validate that the new value (submitted in the form by the user) conforms to the rules for this component. If not, it should invoke notifyDelegate(ValidationConstraint, String).

If the value is acceptible, then the component should update through its parameter (this is very component specific).


notifyDelegate

protected void notifyDelegate(ValidationConstraint constraint,
                              java.lang.String defaultErrorMessage)
Invoked (from update(String), usually} to indicate an error converting from the submitted text value to the appropriate data value.

Sets the error flag to true, then invokes IValidationDelegate.invalidField(IValidatingTextField, ValidationConstraint, String) to tell the listener that there was an error.


getError

public boolean getError()
Returns true if there was a validation error.
Specified by:
getError in interface IValidatingTextField

setError

public void setError(boolean value)
Allows the error state to be set externally. This may occur if two fields are validated against each other (for example, two DateFields that specify a range).
Specified by:
setError in interface IValidatingTextField

pageDetached

public void pageDetached(PageEvent event)
Clear the error, text and delegate properties at the end of request cycle.
Specified by:
pageDetached in interface PageDetachListener
Since:
1.0.5

refresh

public void refresh()
Forces the component to re-read through its text binding. Normally this only occurs once per request cycle. This clears the text property, but not the error property.
Specified by:
refresh in interface IValidatingTextField

render

public void render(IResponseWriter writer,
                   IRequestCycle cycle)
            throws RequestCycleException
Renders the component, which involves the delegate.

During a render, the first field rendered that is either in error, or required but null gets special treatment. JavaScript is added to select that field (such that the cursor jumps right to the field when the page loads).

Specified by:
render in interface IRender
Overrides:
render in class AbstractTextField

beforeCloseTag

protected void beforeCloseTag(IResponseWriter writer,
                              IRequestCycle cycle)
                       throws RequestCycleException
Invokes IValidationDelegate.writeAttributes(IValidatingTextField,IResponseWriter,IRequestCycle).
Overrides:
beforeCloseTag in class AbstractTextField

getRequiredBinding

public IBinding getRequiredBinding()

setRequiredBinding

public void setRequiredBinding(IBinding value)

isRequired

public boolean isRequired()
Returns the value of the required parameter, or false if the parameter is not bound.
Specified by:
isRequired in interface IValidatingTextField