Class FormField

java.lang.Object
org.jivesoftware.smackx.xdata.FormField
All Implemented Interfaces:
org.jivesoftware.smack.packet.Element, org.jivesoftware.smack.packet.NamedElement, org.jivesoftware.smack.packet.XmlElement, org.jivesoftware.smack.packet.XmlLangElement
Direct Known Subclasses:
AbstractMultiFormField, JidMultiFormField, SingleValueFormField

public abstract class FormField extends Object implements org.jivesoftware.smack.packet.XmlElement
Represents a field of a form. The field could be used to represent a question to complete, a completed question or a data returned from a search. The exact interpretation of the field depends on the context where the field is used.

Fields have a name, which is stored in the 'var' attribute of the field's XML representation. Field instances of all types, except of type "fixed" must have a name.

  • Field Details

  • Constructor Details

  • Method Details

    • getDescription

      public String getDescription()
      Returns a description that provides extra clarification about the question. This information could be presented to the user either in tool-tip, help button, or as a section of text before the question.

      If the question is of type FIXED then the description should remain empty.

      Returns:
      description that provides extra clarification about the question.
    • getLabel

      public String getLabel()
      Returns the label of the question which should give enough information to the user to fill out the form.
      Returns:
      label of the question.
    • isRequired

      public boolean isRequired()
      Returns true if the question must be answered in order to complete the questionnaire.
      Returns:
      true if the question must be answered in order to complete the questionnaire.
    • getType

      public FormField.Type getType()
      Returns an indicative of the format for the data to answer.
      Returns:
      format for the data to answer.
      See Also:
    • getValues

      public List<? extends CharSequence> getValues()
      Returns a List of the default values of the question if the question is part of a form to fill out. Otherwise, returns a List of the answered values of the question.
      Returns:
      a List of the default values or answered values of the question.
    • getRawValues

      public abstract List<FormField.Value> getRawValues()
    • getRawValueCharSequences

      public final List<CharSequence> getRawValueCharSequences()
    • hasValueSet

      public boolean hasValueSet()
    • getValuesAsString

      public List<String> getValuesAsString()
      Returns the values a String. Note that you should use getValues() whenever possible instead of this method.
      Returns:
      a list of Strings representing the values
      Since:
      4.3
      See Also:
    • getFirstValue

      public String getFirstValue()
      Returns the first value of this form field or null.
      Returns:
      the first value or null
      Since:
      4.3
    • getFirstValueAsDate

      public Date getFirstValueAsDate() throws ParseException
      Parses the first value of this form field as XEP-0082 date/time format and returns a date instance or null.
      Returns:
      a Date instance representing the date/time information of the first value of this field.
      Throws:
      ParseException - if parsing fails.
      Since:
      4.3.0
    • getFieldName

      public String getFieldName()
      Returns the field's name, also known as the variable name in case this is an filled out answer form.

      According to XEP-4 § 3.2 the variable name (the 'var' attribute) "uniquely identifies the field in the context of the form" (if the field is not of type 'fixed', in which case the field "MAY possess a 'var' attribute")

      Returns:
      the field's name.
    • getFormFieldChildElement

      public FormFieldChildElement getFormFieldChildElement(QName qname)
    • getFormFieldChildElements

      public List<FormFieldChildElement> getFormFieldChildElements(QName qname)
    • getFormFieldChildElements

      public List<FormFieldChildElement> getFormFieldChildElements()
    • getElementName

      public String getElementName()
      Specified by:
      getElementName in interface org.jivesoftware.smack.packet.NamedElement
    • getNamespace

      public String getNamespace()
      Specified by:
      getNamespace in interface org.jivesoftware.smack.packet.XmlElement
    • getQName

      public QName getQName()
      Specified by:
      getQName in interface org.jivesoftware.smack.packet.XmlElement
    • populateExtraXmlChildElements

      protected void populateExtraXmlChildElements()
      Populate extraXmlChildElements. Note that this method may be overridden by subclasses.
    • toXML

      public final org.jivesoftware.smack.util.XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace)
      Specified by:
      toXML in interface org.jivesoftware.smack.packet.Element
    • toXML

      public final org.jivesoftware.smack.util.XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace, boolean includeType)
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • booleanBuilder

      public static BooleanFormField.Builder booleanBuilder(String fieldName)
    • fixedBuilder

      public static TextSingleFormField.Builder fixedBuilder()
    • fixedBuilder

      public static TextSingleFormField.Builder fixedBuilder(String fieldName)
    • hiddenBuilder

      public static TextSingleFormField.Builder hiddenBuilder(String fieldName)
    • jidMultiBuilder

      public static JidMultiFormField.Builder jidMultiBuilder(String fieldName)
    • jidSingleBuilder

      public static JidSingleFormField.Builder jidSingleBuilder(String fieldName)
    • listMultiBuilder

      public static ListMultiFormField.Builder listMultiBuilder(String fieldName)
    • listSingleBuilder

      public static ListSingleFormField.Builder listSingleBuilder(String fieldName)
    • textMultiBuilder

      public static TextMultiFormField.Builder textMultiBuilder(String fieldName)
    • textPrivateBuilder

      public static TextSingleFormField.Builder textPrivateBuilder(String fieldName)
    • textSingleBuilder

      public static TextSingleFormField.Builder textSingleBuilder(String fieldName)
    • builder

      public static TextSingleFormField.Builder builder(String fieldName)
    • buildHiddenFormType

      public static TextSingleFormField buildHiddenFormType(String formType)
    • ifPossibleAs

      public <F extends FormField> F ifPossibleAs(Class<F> formFieldClass)
    • ifPossibleAsOrThrow

      public <F extends FormField> F ifPossibleAsOrThrow(Class<F> formFieldClass)
    • asHiddenFormTypeFieldIfPossible

      public TextSingleFormField asHiddenFormTypeFieldIfPossible()