Page History
Table of Contents |
---|
Introduction
Magnolia 5.1 introduce a new way to handle properties bound to a dialog field. Until Magnolia 5.1 the only way to modify the default behavior (a field is bound to a simple property) was to override the FieldBuilder.getOrCreateProperty(..
method.
Now by configuration we have the possibility to define custom way to read and write a value or values from a property linked to a field. This is us full for complex fields like MultiValueField
or CompositeField
that needs more than one simple property bound to them.
Basic Concept
A Field
is linked to a Property
used to store the field value. This Property
:
...
Another good example for illustrating the Transformer
behavior is the MultiValueField.
The the related field Property
can no more be a simple Property
but rather a complex property containing several values. This property is a PropertysetItemt
(a Property
containing several Property
).
Mockup | ||||
---|---|---|---|---|
|
The way values of the ListProperty
are set and retrieve from the related Item
is also something we would like to configure. For example I may want to have a MultiField
composed of DateField
stored in a single multi value.
The same field may be used in another place but the values have to be stored as sub item (nodes) elements. PropertyHandler
is the second information needed. PropertyHandler
handle the way property element are retrieve and set to an Item
.
Configuration
previous mockup display a Date multi value field (3). This field is associated to a PropertysetItemt
that contains the individual Date Property
. This property delegate the read and write to a Transformer
(1) This Transformer
knows how to read and write the individual Date Property
from and to the related form item. In this example the Transformer
is bound to an Item property of type list. This introduce another big advantage of the Transformer
's. For the same field it is possible to define several read/write strategy:
Store the field values into a single array, or into sub items, ...
Configuration
This These configurations are done in the common fields Properties.
Property | Description | Default value | Valid values | ||||||
---|---|---|---|---|---|---|---|---|---|
transformerClass | Concrete implementation of | propertyBuilder | Concrete property Type and Handler definition. Optional. | propertyHandler | Implementation class of PropertyHandler set to the propertyType used to set and get values in certain format. | ||||
propertyType | Implementation class of CustomPropertyType set as Field PropertyDatasource . |
Default behavior
Basic
...
Field
By default BasicProperty
and BasicPropertyHandler
are used, basic fields (Textm Date, Checkbox,...) uses BasicTransformer
.
The field is created based on the related form Item
. BasicPropertyHandler
BasicTransformer
will:
- Retrieve the
Item.property
if thisproperty
already exist on theItem
.property
is search based on the Field name defined as name property on the field definition. - Create the
Item.property
if thisproperty
do not yet exist on theItem
.property
is created based on the following field definition:type
:property
will get the desiredtype
defaultValue
: if define, the string representation of the default field value is converted to a newtyped value.
Composite
...
Fields
Composite Property (CompositeProperty
Composite Transformer
(CompositeTransformer SwitchableTransformer
) are used by the following fields:
CompositeField
SwitchableField
CompositeField
CompositeField
This field is use by default bound with SimplePropertyCompositeHandler
. This handler the
. This CompositeTransformer
Transformer
will store each single field part of the CompositeField
as single suffixed property.
Assume that your CompositeField
is called 'composite' and contains two fields: a text field called 'simpleText' and a date field called 'simpleDate'. The values will be stored as following:
Advanced Tables - Table Plus | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
|
...
SwitchableField
SwitchableField
This field is used by default bound with SwitchableSimplePropertyCompositeHandler
the
. This handler SwitchableTransformer
Transformer
will store each single field part of the SwitchableField
as single suffixed property.
Assume that your SwitchableField
is called 'switchable' and contains two fields: a text field called 'simpleText' and a date field called 'simpleDate'. The values will be stored as following:
Advanced Tables - Table Plus | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
| |||||||||||
|
List Property
Multi-Value Field
Multi-Value Transformer
List Property (ListProperty
) are used by the following field:
MultiField
MultiField
This field is by default bound with MultiValuesPropertyMultiHandler
MultiValueTransformer
. This handler This Transformer
will store each single field part of the MultiField
as a multiValue property (Basically a JCR multiValue property represented a a Typed List property).
i18n
All default Transformer
implementation support the i18n definition.
If for example you have two language defined ('en', 'de') with 'en' set as default language:
Advanced Tables - Table Plus | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| |||||||||||||||||
|
If you want to implement create your own implementation of PropertyHandler
Transformer
that support i18n, your implementation will need to:
- return
true
for PropertyHandler forTransformer
.hasI18NSupport() - implement a compatible Magnolia i18n logic.
Default Value
ConfiguredFieldDefinition.defaultValue
contains the String representation of the default value.
The default value is only showed the first time the related form is displayed.
This behavior is only supported by basic field .
Implemented
...
Implemented Property
...
Property
A field needs to be linked to a property as data source. The value of the property is used to store the value entered/selected by the user on the field.
In Magnolia 5.1, every field are bound to a property that support Transformer
called TransformedProperty
.
This property is initialized with the configured Transformer
and set to the field as datasource by the FieldFactory
.
Mockup | ||
---|---|---|
|
BaseProperty
BaseProperty
implements the following basic mechanism:
- Handle i18n support.
- Delegate the configured
handler
the request whenproperty.getValue()
andproperty.setValue()
are called.
Implemented Handlers
BasicPropertyHandler
Overview
Mockup | ||
---|---|---|
|
...
|
A ConfiguredField is linked to a TransformedProperty<T>
.
TransformedProperty<T>
is initialized with aTransformer
.
TransformedProperty<T>
extend ObjectProperty<T>
.
- value T :
Transformer.readFromItem()
- T :
Transformer.getType()
The Transformer
has the responsibility to retrieve the initial value and to set the property class type.
TransformedProperty<T>
may be of any type. For a TextField configured to handle Long (ConfiguredFieldDefinition.type = Long
), the <T>
will be of type Long
.
For complexer Field (Multi, Composite) the <T>
is of type PropertysetItem
. This let the complex field easily handle multi property.
Implemented Transformer
BasicTransformer
The property
linked to a field is retrieved and stored based on the Field's property name
defined in the field definition.
A new property
is created in case id does not yet exist.
...
Advanced Tables - Table Plus | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
| |||||||||||
|
OptionGroupPropertyHandler
In case of an OptionGroup
field is defined as multiselect
, the selected values are stored as a JCR multi-value-property. This JCR multi-value-property is normally handled as a List,
but the underlying Vaadin field is only working with Set
. This handler simply convert List
to Set
.
TextCodePropertyHandler
Simple TextCode Handler that return an empty String
instead of a null property
value.
TwinSelectPropertyHandler
Like for the OptionGroup
field, the underlying Vaadin Field need additional convertor between List
to Set
.
CompositeHandler
CompositeTransformer
In In addition to the CompositeField
and SwitchableField
default Handler
Transformer
, we provide two an additional CompositeHandler
Transformer
:
SubNodeCompositeHandler
SubNodeCompositeHandler
will store the property
values of the fields composing the composite field under the following format:
...
enableHeadingAttributes | false |
---|---|
enableSorting | false |
class | m5-configuration-tree |
enableHighlighting | false |
...
formNode
...
...
Second field name composing the
Composite field
...
NoOpCompositeTransformer
NoOpCompositeTransformer
...
Third field name composing the
Composite field
...
This Handler
do not support i18n
(in Magnolia 5.1).
NoOpCompositeHandler
NoOpCompositeHandler
is useful if you want to combine a Multi filed storing individual field value into sub nodes with composite field as Multi field component.
Mockup | ||
---|---|---|
|
In this case, the Multi field handler field
will createread/read write the node Item structure and pass a properties as Transformer
PropertysetItem
to the NoOpCompositeHandler
NoOpCompositeTransformer
. This handler This
just act as a property container. Transformer
MultiTransformer
MultiHandler
...
MultiValueTransformer
This is the default Handler
default
set for Multi value fields. The fields values are stored in a Transformer
. This LinkedList
<T>
is then automatically convert to a JCR multi-value-property once it is persisted. LinkedList
<T>
This will only work for simple fields like text/date/radio...
...
MultiValueJSONTransformer
Handler
storing
storing the fields values as a Transformer
String
with ',' as separator.
This will only work for simple fields like text/date/radio... and values are stored as String
.
...
MultiValueChildrenNodeTransformer
Handler
storing the fields values in sub node item property: (Equivalent Jcr Structure of the form Item)Transformer
Advanced Tables - Table Plus | |||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| |||||||||||||||||||||||||||||||
|
SubNodesMultiPropertysetItemHandler
MultiValueSubChildrenNodePropertiesTransformer
storing each field values into a sub Item. Equivalent to Transformer
MultiValueChildrenNodeTransformer
but this
is able to handle multiple values. Based on the previous Transformer
NoOpCompositeHandler
o previous NoOpCompositeTransformer
example:
Advanced Tables - Table Plus | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
...
MultiValueSubChildrenNodeTransformer
Handler
creating
creating first a child node (named as the multi field) and storing the fields values in sub node property (equivalent to Transformer
MultiValueChildrenNodeTransformer
) :
Advanced Tables - Table Plus | |||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| |||||||||||||||||||||||||||||||||||
|
Limitation
How to
Open Issue
Default value handling
The field definition allows to define a default value as a String:
- Text field, type is String default value is 'default value'
- Text field, type is Long default value is 1000l
- ....
This default value should be displayed in the related form field if ????
- It is a new Form
- easy to implement
- if a field is added to an existing form, this default value will never be displayed.
- chooses solution
- If the property related to a form is null (currently if a property has an empty value, this property is removed or not saved)
- easy to implement
- if a user remove the default value associated to a field --> no property saved. When he will reopen this form, the default value will be displayed again
- ??
...