The RadDataForm contains many built-in property editors that are either automatically resolved depending on the property's type or by the associated annotation @DataFormProperty editor
. The RadDataForm currently ships with the following built-in editors:
The RadDataForm 'annotations' can be used to easily assign an editor to a property of the set Entity. The next example demonstrates how to set the editor of a property via the described annotations:
@DataFormProperty(
label = "From",
index = 0,
editor = DataFormRadAutoCompleteEditor.class
)
public String[] getFrom() {
return from;
}
public void setFrom(String[] value) {
from = value;
notifyListeners("From", value);
}
The DataFormRadAutoCompleteEditor is a bit more advanced editor which provides an out of the box quick search functionality. This editor uses the RadAutoCompleteTextView stand alone element and all its functionality like DisplayMode
is available to the RadDataForm editor.
Because of the nature of the RadAutoCompleteTextView the editor which exposes its functionality requires some additional data to be passed to it which will be used as the 'suggestions' when a user starts typing in its text box.
Passing this data can be done in multiple different approaches depending on which one is the easiest for your scenario:
additionalData
property of the @DataFormProperty and setting it to an static String[]
AutoCompleteAdapter
and setting it to the DataFormRadAutoCompleteEditor via its setAdapter()
methodOr by directly by calling the updateValues()
of the specific EntityPropertyCore
object. The next code snippet shows how you can use the mentioned 'updateValues' method on an existing 'from' property of the RadDataForm, the list
object is a simple List<String>
:
((EntityPropertyCore)this.dataForm.getPropertyByName("From")).updateValues(list.toArray());
Because calling the updateValues can be done after the editor has been rendered you need to make sure you also update the DataFormRadAutoCompleteEditor itself by simply calling its updateAdapter()
method:
fromEditor.updateAdapter();
If you are familiar with the RadAutoCompleteTextView element you know that is supports out of the box two different selected items display modes:
When using the DataFormRadAutoCompleteEditor
you too have the option to change the editor's displayMode
by simply calling its setDisplayMode()
and passing the desired mode:
fromEditor.setDisplayMode(DisplayMode.TOKENS);
When the displayMode is set to TOKEN
if the bound to that editor property of your EntityProperty is of type String[]
and each of its elements is present in the "suggestion source" those items from the array will be rendered as separate tokens.
The full Java source code of the above example can be found here.