Class 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 java.lang.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 Detail

      • QNAME

        public static final javax.xml.namespace.QName QNAME
      • FORM_TYPE

        public static final java.lang.String FORM_TYPE
        The constant String "FORM_TYPE".
        See Also:
        Constant Field Values
      • extraXmlChildElements

        protected transient java.util.List<org.jivesoftware.smack.packet.XmlElement> extraXmlChildElements
    • Method Detail

      • getDescription

        public java.lang.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 java.lang.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:
        FormField.Type
      • getValues

        public java.util.List<? extends java.lang.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 java.util.List<FormField.Value> getRawValues()
      • getRawValueCharSequences

        public final java.util.List<java.lang.CharSequence> getRawValueCharSequences()
      • hasValueSet

        public boolean hasValueSet()
      • getValuesAsString

        public java.util.List<java.lang.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:
        getValues()
      • getFirstValue

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

        public java.util.Date getFirstValueAsDate()
                                           throws java.text.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:
        java.text.ParseException - if parsing fails.
        Since:
        4.3.0
      • getVariable

        @Deprecated
        public java.lang.String getVariable()
        Deprecated.
        use getFieldName() instead.
        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.
      • getFieldName

        public java.lang.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​(javax.xml.namespace.QName qname)
      • getFormFieldChildElements

        public java.util.List<FormFieldChildElement> getFormFieldChildElements​(javax.xml.namespace.QName qname)
      • getElementName

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

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

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

        protected void populateExtraXmlChildElements()
        Populate @{link 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​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • buildHiddenFormType

        public static TextSingleFormField buildHiddenFormType​(java.lang.String formType)
      • ifPossibleAs

        public <F extends FormField> F ifPossibleAs​(java.lang.Class<F> formFieldClass)
      • ifPossibleAsOrThrow

        public <F extends FormField> F ifPossibleAsOrThrow​(java.lang.Class<F> formFieldClass)
      • asHiddenFormTypeFieldIfPossible

        public TextSingleFormField asHiddenFormTypeFieldIfPossible()