org.apache.tapestry.form.translator
Class AbstractTranslator

java.lang.Object
  extended by org.apache.tapestry.form.AbstractFormComponentContributor
      extended by org.apache.tapestry.form.translator.AbstractTranslator
All Implemented Interfaces:
FormComponentContributor, Translator
Direct Known Subclasses:
BigDecimalTranslator, FormatTranslator, StringTranslator

public abstract class AbstractTranslator
extends AbstractFormComponentContributor
implements Translator

Abstract Translator implementation that provides default behavior for trimming, null object, and empty text handling.

Since:
4.0
Author:
Paul Ferraro

Constructor Summary
AbstractTranslator()
           
AbstractTranslator(String initializer)
           
 
Method Summary
protected  String buildMessage(ValidationMessages messages, IFormComponent field, String key)
           
 String format(IFormComponent field, Locale locale, Object object)
          Invoked during rendering to format an object (which may be null) into a text value (which should not be null) appropriate for the specified field.
protected abstract  String formatObject(IFormComponent field, Locale locale, Object object)
           
 String getMessage()
           
protected  Object[] getMessageParameters(Locale locale, String label)
           
protected  Object getValueForEmptyInput()
          The value to be used when the value supplied in the request is blank (null or empty).
 boolean isTrim()
           
 Object parse(IFormComponent field, ValidationMessages messages, String text)
          Invoked during rewind to parse a submitted input value into an object suitable for the specified component.
protected abstract  Object parseText(IFormComponent field, ValidationMessages messages, String text)
           
 void renderContribution(IMarkupWriter writer, IRequestCycle cycle, FormComponentContributorContext context, IFormComponent field)
          Invoked by a form component after it finishes rendering its tag (but before the tag is closed) to allow this object to contribute to the component's rendering process.
 void setMessage(String message)
           
 void setTrim(boolean trim)
           
 
Methods inherited from class org.apache.tapestry.form.AbstractFormComponentContributor
accumulateProfileProperty, accumulateProperty, defaultScript, getScript, setScript
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractTranslator

public AbstractTranslator()

AbstractTranslator

public AbstractTranslator(String initializer)
Method Detail

format

public String format(IFormComponent field,
                     Locale locale,
                     Object object)
Description copied from interface: Translator
Invoked during rendering to format an object (which may be null) into a text value (which should not be null) appropriate for the specified field.

Specified by:
format in interface Translator
locale - TODO
See Also:
Translator.format(org.apache.tapestry.form.IFormComponent, Locale, java.lang.Object)

parse

public Object parse(IFormComponent field,
                    ValidationMessages messages,
                    String text)
             throws ValidatorException
Description copied from interface: Translator
Invoked during rewind to parse a submitted input value into an object suitable for the specified component.

Specified by:
parse in interface Translator
messages - TODO
Returns:
the parsed object
Throws:
ValidatorException - if the specified text could not be parsed into an object.
See Also:
Translator.parse(org.apache.tapestry.form.IFormComponent, ValidationMessages, java.lang.String)

formatObject

protected abstract String formatObject(IFormComponent field,
                                       Locale locale,
                                       Object object)

parseText

protected abstract Object parseText(IFormComponent field,
                                    ValidationMessages messages,
                                    String text)
                             throws ValidatorException
Throws:
ValidatorException

getValueForEmptyInput

protected Object getValueForEmptyInput()
The value to be used when the value supplied in the request is blank (null or empty). The default value is null, but some subclasses may override.

Returns:
null, subclasses may override
See Also:
parse(IFormComponent, ValidationMessages, String)

buildMessage

protected String buildMessage(ValidationMessages messages,
                              IFormComponent field,
                              String key)

getMessageParameters

protected Object[] getMessageParameters(Locale locale,
                                        String label)

renderContribution

public void renderContribution(IMarkupWriter writer,
                               IRequestCycle cycle,
                               FormComponentContributorContext context,
                               IFormComponent field)
Description copied from interface: FormComponentContributor
Invoked by a form component after it finishes rendering its tag (but before the tag is closed) to allow this object to contribute to the component's rendering process. Typically used by Validators and Translators to add javascript methods to the form's submit event handler.

Specified by:
renderContribution in interface FormComponentContributor
Overrides:
renderContribution in class AbstractFormComponentContributor
Parameters:
writer - allows contributor to write additional attributes into the component's tag
cycle - for accessing request information
context - utilities for genering messages and client-side validation
field - the field for which contributions are being rendered
See Also:
FormComponentContributor.renderContribution(IMarkupWriter, IRequestCycle, FormComponentContributorContext, IFormComponent)

isTrim

public boolean isTrim()

setTrim

public void setTrim(boolean trim)

getMessage

public String getMessage()

setMessage

public void setMessage(String message)


Copyright © 2006-2008 Apache Software Foundation. All Rights Reserved.