public static final class DataForm.Field extends java.lang.Object implements java.lang.Comparable<DataForm.Field>
A data form field.
// <field type="boolean" var="test"><value>1</value></field>
DataForm.Field field = DataForm.Field.builder()
.var("test")
.value(true)
.build();
// <field type="jid-single" var="test"><value>domain</value></field>
DataForm.Field.builder()
.var("test")
.value(Jid.of("domain"))
.build();
// <field type="list-single" var="test"><option><value>option</value></option></field>
DataForm.Field field = DataForm.Field.builder()
.var("test")
.type(DataForm.Field.Type.LIST_SINGLE)
.options(Collections.singleton(new DataForm.Option("option")))
.build();
// 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();
This class is immutable.
Modifier and Type | Class and Description |
---|---|
static class |
DataForm.Field.Builder
A builder class to build a data form field.
|
static class |
DataForm.Field.Type
Defines field types.
|
Modifier and Type | Method and Description |
---|---|
static DataForm.Field.Builder |
builder()
Creates the builder to build a data form field.
|
int |
compareTo(DataForm.Field o) |
java.lang.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).
|
java.lang.String |
getLabel()
Gets the field label.
|
Media |
getMedia()
Gets the media element.
|
java.util.List<DataForm.Option> |
getOptions()
Gets the options if the field type is
DataForm.Field.Type.LIST_SINGLE or DataForm.Field.Type.LIST_MULTI . |
DataForm.Field.Type |
getType()
Gets the field type.
|
Validation |
getValidation()
Gets the validation for this field.
|
java.lang.String |
getValue()
Gets the value of the field.
|
boolean |
getValueAsBoolean()
Gets the value as boolean.
|
java.time.Instant |
getValueAsInstant()
Returns the first value as date.
|
java.lang.Integer |
getValueAsInteger()
Returns the first value as integer.
|
Jid |
getValueAsJid()
Returns the first value as JID, e.g. for the
DataForm.Field.Type.JID_SINGLE field type. |
java.util.List<java.lang.String> |
getValues()
Gets the values of the field.
|
java.util.List<Jid> |
getValuesAsJid()
Returns a JID list for the
DataForm.Field.Type.JID_MULTI field type. |
java.lang.String |
getVar()
Gets a unique identifier for the field in the context of the form.
|
boolean |
isRequired()
If the field as required in order for the form to be considered valid.
|
java.lang.String |
toString() |
public static DataForm.Field.Builder builder()
Creates the builder to build a data form field.
public final DataForm.Field.Type getType()
Gets the field type.
public final java.lang.String getVar()
Gets a unique identifier for the field in the context of the form.
public final java.lang.String getLabel()
Gets the field label.
public final java.util.List<DataForm.Option> getOptions()
Gets the options if the field type is DataForm.Field.Type.LIST_SINGLE
or DataForm.Field.Type.LIST_MULTI
.
public final java.util.List<java.lang.String> getValues()
Gets the values of the field. Fields of type DataForm.Field.Type.LIST_MULTI
, DataForm.Field.Type.JID_MULTI
or DataForm.Field.Type.TEXT_MULTI
may contain multiple values.
public final java.lang.String getValue()
Gets the value of the field.
public final boolean getValueAsBoolean()
Gets the value as boolean.
public final java.lang.Integer getValueAsInteger()
Returns the first value as integer.
public final java.time.Instant getValueAsInstant()
Returns the first value as date.
public final java.util.List<Jid> getValuesAsJid()
Returns a JID list for the DataForm.Field.Type.JID_MULTI
field type.
public final Jid getValueAsJid()
Returns the first value as JID, e.g. for the DataForm.Field.Type.JID_SINGLE
field type.
public final Media getMedia()
Gets the media element.
public final java.lang.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).
public final Validation getValidation()
Gets the validation for this field.
public final boolean isRequired()
If the field as required in order for the form to be considered valid.
public final int compareTo(DataForm.Field o)
compareTo
in interface java.lang.Comparable<DataForm.Field>
public final java.lang.String toString()
toString
in class java.lang.Object
Copyright © 2014–2019 XMPP.rocks. All rights reserved.