Package org.apache.tapestry5
Interface Translator<T>
- Type Parameters:
T
- the type being translated
- All Known Implementing Classes:
AbstractTranslator
,NumericTranslator
,StringTranslator
public interface Translator<T>
Translates between client-side and server-side values. Client-side values are always strings.
-
Method Summary
Modifier and TypeMethodDescriptionReturns the message key, within the application's global message catalog, normally used by this validator.getName()
Returns a unique name for the translator.getType()
Returns the type of the server-side value.parseClient
(Field field, String clientValue, String message) Converts a submitted request value into an appropriate server side value.void
render
(Field field, String message, MarkupWriter writer, FormSupport formSupport) Hook used by components to allow the validator to contribute additional attributes or (more often) client-side JavaScript (via theFormSupport.addValidation(Field, String, String, Object)
).Converts a server-side value to a client-side string.
-
Method Details
-
getName
Returns a unique name for the translator. This is used to identify the translator by name, but is also used when locating override messages for the translator.- Returns:
- unique name for the translator
-
toClient
Converts a server-side value to a client-side string. This allows for formatting of the value in a way appropriate to the end user. The output client value should be parsable byparseClient(Field, String, String)
.- Parameters:
value
- the server side value (which will not be null)- Returns:
- client-side value to present to the user
-
getType
Returns the type of the server-side value.- Returns:
- a type
-
getMessageKey
Returns the message key, within the application's global message catalog, normally used by this validator. This is used to provide the formatted message toparseClient(Field, String, String)
orrender(Field, String, MarkupWriter, org.apache.tapestry5.services.FormSupport)
.- Returns:
- a message key
-
parseClient
Converts a submitted request value into an appropriate server side value.- Parameters:
field
- for which a value is being parsedclientValue
- to convert to a server value; this will not be null, but may be blankmessage
- formatted validation message, either from validation messages, or from an override- Returns:
- equivalent server-side value (possibly null)
- Throws:
ValidationException
- if the value can not be parsed
-
render
Hook used by components to allow the validator to contribute additional attributes or (more often) client-side JavaScript (via theFormSupport.addValidation(Field, String, String, Object)
).- Parameters:
field
- the field which is currently being renderedmessage
- formatted validation message, either from validation messages, or from an overridewriter
- markup writer, allowing additional attributes to be written into the active elementformSupport
- used to add JavaScript
-