Class DataForm.Field

  • All Implemented Interfaces:
    Enclosing class:

    public static final class DataForm.Field
    extends Object
    implements Comparable<DataForm.Field>
    A data form field.


    Creating a field

    Since 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()
     // <field type="jid-single" var="test"><value>domain</value></field>

    Creating a field with options

     // <field type="list-single" var="test"><option><value>option</value></option></field>
     DataForm.Field field = DataForm.Field.builder()
         .options(Collections.singleton(new DataForm.Option("option")))

    Retrieving values from a field

     // 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.
    See Also:
    3.2 The Field Element
    • Method Detail

      • builder

        public static DataForm.Field.Builder builder()
        Creates the builder to build a data form field.
        The builder.
      • getType

        public final DataForm.Field.Type getType()
        Gets the field type.
        The field type.
      • getName

        public final String getName()
        Gets a unique identifier for the field in the context of the form.
        The var attribute.
      • getVar

        public final String getVar()
        Deprecated, for removal: This API element is subject to removal in a future version.
        Gets a unique identifier for the field in the context of the form.
        The var attribute.
      • getLabel

        public final String getLabel()
        Gets the field label.
        The label.
      • getValue

        public final String getValue()
        Gets the value of the field.
        The value.
      • getValueAsBoolean

        public final boolean getValueAsBoolean()
        Gets the value as boolean.
        The value as boolean.
      • getValueAsInteger

        public final Integer getValueAsInteger()
        Returns the first value as integer.
        The integer or null, if the values are empty.
      • getValueAsInstant

        public final Instant getValueAsInstant()
        Returns the first value as date.
        The date or null, if the values are empty.
      • getValueAsJid

        public final Jid getValueAsJid()
        Returns the first value as JID, e.g. for the DataForm.Field.Type.JID_SINGLE field type.
        The JID or null, if the values are empty.
      • getMedia

        public final Media getMedia()
        Gets the media element.
        The media element.
      • getDescription

        public 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).
        The description.
      • isRequired

        public final boolean isRequired()
        If the field as required in order for the form to be considered valid.
        True, if the field is required.
      • hashCode

        public final int hashCode()
        hashCode in class Object