Package rocks.xmpp.extensions.data.model
Class DataForm.Field
- java.lang.Object
- 
- rocks.xmpp.extensions.data.model.DataForm.Field
 
- 
- All Implemented Interfaces:
- Comparable<DataForm.Field>
 - Enclosing class:
- DataForm
 
 public static final class DataForm.Field extends Object implements Comparable<DataForm.Field> A data form field.UsageCreating a fieldSince a field can have multiple different properties like type, value, label, description, required, options, etc. it uses the builder pattern to construct an (immutable) instance of a field. If the field type is omitted it's inferred from the value, as you see in the following examples.// <field type="boolean" var="test"><value>1</value></field> DataForm.Field field = DataForm.Field.builder() .name("test") .value(true) .build(); // <field type="jid-single" var="test"><value>domain</value></field> DataForm.Field.builder() .name("test") .value(Jid.of("domain")) .build();Creating a field with options// <field type="list-single" var="test"><option><value>option</value></option></field> DataForm.Field field = DataForm.Field.builder() .name("test") .type(DataForm.Field.Type.LIST_SINGLE) .options(Collections.singleton(new DataForm.Option("option"))) .build();Retrieving values from a field
 This class is immutable.// Interprets the field value as integer, e.g. <value>123</value> Integer intValue = field.getValueAsInteger(); // Interprets the field value as boolean, e.g. <value>1</value> boolean boolValue = field.getValueAsBoolean();- See Also:
- 3.2 The Field Element
 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classDataForm.Field.BuilderA builder class to build a data form field.static classDataForm.Field.TypeDefines field types.
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static DataForm.Field.Builderbuilder()Creates the builder to build a data form field.intcompareTo(DataForm.Field o)booleanequals(Object o)StringgetDescription()Gets a natural-language description of the field, intended for presentation in a user-agent (e.g., as a "tool-tip", help button, or explanatory text provided near the field).StringgetLabel()Gets the field label.MediagetMedia()Gets the media element.StringgetName()Gets a unique identifier for the field in the context of the form.List<DataForm.Option>getOptions()Gets the options if the field type isDataForm.Field.Type.LIST_SINGLEorDataForm.Field.Type.LIST_MULTI.DataForm.Field.TypegetType()Gets the field type.ValidationgetValidation()Gets the validation for this field.StringgetValue()Gets the value of the field.booleangetValueAsBoolean()Gets the value as boolean.InstantgetValueAsInstant()Returns the first value as date.IntegergetValueAsInteger()Returns the first value as integer.JidgetValueAsJid()Returns the first value as JID, e.g. for theDataForm.Field.Type.JID_SINGLEfield type.List<String>getValues()Gets the values of the field.List<Jid>getValuesAsJid()Returns a JID list for theDataForm.Field.Type.JID_MULTIfield type.StringgetVar()Deprecated, for removal: This API element is subject to removal in a future version.UsegetName()inthashCode()booleanisRequired()If the field as required in order for the form to be considered valid.StringtoString()
 
- 
- 
- 
Method Detail- 
builderpublic static DataForm.Field.Builder builder() Creates the builder to build a data form field.- Returns:
- The builder.
 
 - 
getTypepublic final DataForm.Field.Type getType() Gets the field type.- Returns:
- The field type.
 
 - 
getNamepublic final String getName() Gets a unique identifier for the field in the context of the form.- Returns:
- The var attribute.
 
 - 
getVar@Deprecated(forRemoval=true) public final String getVar() Deprecated, for removal: This API element is subject to removal in a future version.UsegetName()Gets a unique identifier for the field in the context of the form.- Returns:
- The var attribute.
 
 - 
getLabelpublic final String getLabel() Gets the field label.- Returns:
- The label.
 
 - 
getOptionspublic final List<DataForm.Option> getOptions() Gets the options if the field type isDataForm.Field.Type.LIST_SINGLEorDataForm.Field.Type.LIST_MULTI.- Returns:
- The options.
 
 - 
getValuespublic final List<String> getValues() Gets the values of the field. Fields of typeDataForm.Field.Type.LIST_MULTI,DataForm.Field.Type.JID_MULTIorDataForm.Field.Type.TEXT_MULTImay contain multiple values.- Returns:
- The values.
 
 - 
getValuepublic final String getValue() Gets the value of the field.- Returns:
- The value.
 
 - 
getValueAsBooleanpublic final boolean getValueAsBoolean() Gets the value as boolean.- Returns:
- The value as boolean.
 
 - 
getValueAsIntegerpublic final Integer getValueAsInteger() Returns the first value as integer.- Returns:
- The integer or null, if the values are empty.
 
 - 
getValueAsInstantpublic final Instant getValueAsInstant() Returns the first value as date.- Returns:
- The date or null, if the values are empty.
 
 - 
getValuesAsJidpublic final List<Jid> getValuesAsJid() Returns a JID list for theDataForm.Field.Type.JID_MULTIfield type.- Returns:
- The JID list.
 
 - 
getValueAsJidpublic final Jid getValueAsJid() Returns the first value as JID, e.g. for theDataForm.Field.Type.JID_SINGLEfield type.- Returns:
- The JID or null, if the values are empty.
 
 - 
getMediapublic final Media getMedia() Gets the media element.- Returns:
- The media element.
 
 - 
getDescriptionpublic final String getDescription() Gets a natural-language description of the field, intended for presentation in a user-agent (e.g., as a "tool-tip", help button, or explanatory text provided near the field).- Returns:
- The description.
 
 - 
getValidationpublic final Validation getValidation() Gets the validation for this field.- Returns:
- The validation.
- See Also:
- XEP-0122: Data Forms Validation
 
 - 
isRequiredpublic final boolean isRequired() If the field as required in order for the form to be considered valid.- Returns:
- True, if the field is required.
 
 - 
compareTopublic final int compareTo(DataForm.Field o) - Specified by:
- compareToin interface- Comparable<DataForm.Field>
 
 
- 
 
-