Class SimpleType
This class is not meant to be created and used, it is actually documentation of settings
allowed in a DataSource descriptor (.ds.xml file), for use with Smart GWT Pro Edition and
above.
See com.smartgwt.client.docs.serverds
for how to use this documentation.
SimpleTypes can be created
at any time, and
subsequently referred
to as a field type
in DataSources
and
DataBoundComponents
. This allows you to
define
validation
, formatting
and editing
behaviors for a
type to be reused across all
DataBoundComponents
.
The SimpleType class also allows data to be stored in some opaque format but treated as
simple atomic values as far as Smart GWT components are concerned by implementing
getAtomicValue()
and updateAtomicValue()
methods.
For example, if some record has a field value set to a javascript object with the
following properties:
{ stringValue:"A String", length: 9 }this value could be treated as a simple string by defining a SimpleType with
inheritsFrom
set to
"text"
and a custom
getAtomicValue()
method that simply extracted the "stringValue"
attribute from the data object. DataBoundComponents would then display
the string value, and use it for sorting and other standard databinding features.
Note that the term "simpleType" is used in the same sense as in
XML Schema, and
XMLTools.loadXMLSchema()
will create
new SimpleType definitions.
When using the Smart GWT Server, SimpleTypes can be defined server-side, and should be defined server-side if validators are going to be declared so that the server will enforce validation. To define server-side SimpleTypes using Component XML you should create file {typeName}.type.xml in the following format:
<SimpleType name="{typeName}" inheritsFrom="{otherSimpleType}" editorType="{FormItemClassName}"> <validators> <!-- validator definition just like DataSourceField --> </validators> </SimpleType>.. and place this file alongside your DataSource files (.ds.xml) files - in any of folders listed in
project.datasources
property in server.properties
.
SimpleTypes can be loaded via DataSourceLoader or loadDS JSP tags
and
should be loaded before the definitions of any DataSources that use them (so
generally put all SimpleType definitions first).
Define validators in the server-side type definition, for example:
<SimpleType name="countryCodeType" inheritsFrom="text"> <validators> <validator type="lengthRange" min="2" max="2" errorMessage="Length of country code should be equal to 2." /> <validator type="regexp" expression="[A-Z][A-Z]" errorMessage="CountryCode should have only uppercase letters." /> </validators> </SimpleType>
For client-side formatters, add these to the type definition after loading it from the server, for example:
SimpleType.getType("independenceDateType").setShortDisplayFormatter(new SimpleTypeFormatter() { public String format(Object value, DataClass field, DataBoundComponent component, Record record) { if (value == null) return null; return "<i>" + (((java.util.Date) value).getYear() + 1900) + "</i>"; } });Note that formatters must be added to the SimpleType definition before any DataBoundComponent binds to a DataSource that uses the SimpleType.
An example is here.
-
Field Summary
Modifier and TypeFieldDescriptionDefault value forDataSourceField.canEdit
for fields of this type.Default value forDataSourceField.canFilter
for fields of this type.In components that support grouping, the default mode from the availablegroupingModes
to use when grouping values of this type.The defaultsearch-operator
for this data-type.Classname of the FormItem that should be the default for editing values of this type (eg "SelectItem").FormatString
used during exports for numeric or date formatting.These are properties that are essentially copied onto any DataSourceField where the property is applied.Classname of the FormItem that should be used to edit values of this type if it appears in a filter row.FormatString
for numeric or date formatting.A set of key-value pairs that represent the names and titles of the grouping modes available to values of this type, for use in components that support grouping.Name of another SimpleType from which this type should inherit.Name of the type, used to refer to the type fromfield.type
.DefaultreadOnlyDisplay
for fields of this type.Classname of the FormItem that should be used to display values of this type when a field is marked ascanEdit false
and the field is displayed in an editor type component like a DynamicForm.Validators to apply to value of this type.Set ofsearch-operators
valid for thisSimpleType
.List of legal values for this type, likeDataSourceField.valueMap
. -
Constructor Summary
-
Method Summary
-
Field Details
-
readOnlyDisplay
DefaultreadOnlyDisplay
for fields of this type.For more sophisticated management of read-only behavior, see
readOnlyEditorType
.Default value is null
-
groupingModes
A set of key-value pairs that represent the names and titles of the grouping modes available to values of this type, for use in components that support grouping.Some types provide a set of builtin groupingModes, as covered
here
.Use
setGroupValueFunction()
andsetGroupTitleFunction()
to implement custom grouping logic for each of the grouping modes you provide.Default value is null
-
inheritsFrom
Name of another SimpleType from which this type should inherit.Validators, if any, will be combined. All other SimpleType properties default to the inherited type's value.
Default value is null
-
name
Name of the type, used to refer to the type fromfield.type
.Default value is null
-
validOperators
Set ofsearch-operators
valid for thisSimpleType
.If not specified, the
inherited
type's operators will be used, finally defaulting to the default operators for the basic types (eg, integer).Default value is null
- See Also:
-
readOnlyEditorType
Classname of the FormItem that should be used to display values of this type when a field is marked ascanEdit false
and the field is displayed in an editor type component like a DynamicForm.May be overridden by
DataSourceField.readOnlyEditorType
.Default value is null
-
canFilter
Default value forDataSourceField.canFilter
for fields of this type.This impacts client-side behavior only and may be used to explicitly enable editing in filter interfaces, even if
editing is disabled
.This property is set to true for the "sequence" SimpleType by default.
Default value is null
-
editorType
Classname of the FormItem that should be the default for editing values of this type (eg "SelectItem").You can create a simple custom FormItem by adding default
FormItem.icons
that launch custom value picking dialogs (an example is in the QuickStart Guide, Chapter 9, Extending Smart GWT). By setting simpleType.editorType to the name of your custom FormItem, forms will automatically use the custom FormItem, as will grids performinginline editing
.Default value is null
-
valueMap
List of legal values for this type, likeDataSourceField.valueMap
.Default value is null
-
defaultGroupingMode
In components that support grouping, the default mode from the availablegroupingModes
to use when grouping values of this type.Default value is null
-
canEdit
Default value forDataSourceField.canEdit
for fields of this type.This impacts client-side behavior only and is a way to simply disallow editing of this field type by default within
editors
.This property is set to false for the "sequence" SimpleType by default.
Default value is null
-
exportFormat
FormatString
used during exports for numeric or date formatting. SeeDataSourceField.exportFormat
.Default value is null
- See Also:
-
filterEditorType
Classname of the FormItem that should be used to edit values of this type if it appears in a filter row.May be overridden by
DataSourceField.filterEditorType
.Default value is null
-
fieldProperties
These are properties that are essentially copied onto any DataSourceField where the property is applied. The supported properties are only client-side properties.Default value is null
-
defaultOperator
The defaultsearch-operator
for this data-type.Default value is null
- See Also:
-
format
- See Also:
-
validators
Validators to apply to value of this type.Default value is null
- See Also:
-
-
Constructor Details
-
SimpleType
public SimpleType()
-