public class FormField
extends java.lang.Object
implements org.jivesoftware.smack.packet.NamedElement
Modifier and Type | Class and Description |
---|---|
static class |
FormField.Option
Represents the available option of a given FormField.
|
static class |
FormField.Type
Form Field Types as defined in XEP-4 § 3.3.
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ELEMENT |
static java.lang.String |
FORM_TYPE
The constant String "FORM_TYPE".
|
Constructor and Description |
---|
FormField()
Creates a new FormField of type FIXED.
|
FormField(java.lang.String variable)
Creates a new FormField with the variable name that uniquely identifies the field
in the context of the form.
|
Modifier and Type | Method and Description |
---|---|
void |
addOption(FormField.Option option)
Adss an available options to the question that the user has in order to answer
the question.
|
void |
addValue(java.lang.CharSequence value)
Adds a default value to the question if the question is part of a form to fill out.
|
void |
addValue(java.util.Date date)
Adds the given Date as XEP-0082 formated string by invoking
addValue(CharSequence) after the date
instance was formated. |
void |
addValues(java.util.List<? extends java.lang.CharSequence> newValues)
Adds a default values to the question if the question is part of a form to fill out.
|
boolean |
equals(java.lang.Object obj) |
java.lang.String |
getDescription()
Returns a description that provides extra clarification about the question.
|
java.lang.String |
getElementName() |
java.lang.String |
getFirstValue()
Returns the first value of this form fold or
null . |
java.util.Date |
getFirstValueAsDate()
Parses the first value of this form field as XEP-0082 date/time format and returns a date instance or
null . |
java.lang.String |
getLabel()
Returns the label of the question which should give enough information to the user to
fill out the form.
|
java.util.List<FormField.Option> |
getOptions()
Returns a List of the available options that the user has in order to answer
the question.
|
FormField.Type |
getType()
Returns an indicative of the format for the data to answer.
|
ValidateElement |
getValidateElement()
Get validate element.
|
java.util.List<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.
|
java.util.List<java.lang.String> |
getValuesAsString()
Returns the values a String.
|
java.lang.String |
getVariable()
Returns the variable name that the question is filling out.
|
int |
hashCode() |
boolean |
isRequired()
Returns true if the question must be answered in order to complete the questionnaire.
|
protected void |
resetValues()
Removes all the values of the field.
|
void |
setDescription(java.lang.String description)
Sets a description that provides extra clarification about the question.
|
void |
setLabel(java.lang.String label)
Sets the label of the question which should give enough information to the user to
fill out the form.
|
void |
setRequired(boolean required)
Sets if the question must be answered in order to complete the questionnaire.
|
void |
setType(FormField.Type type)
Sets an indicative of the format for the data to answer.
|
void |
setValidateElement(ValidateElement validateElement)
Set validate element.
|
org.jivesoftware.smack.util.XmlStringBuilder |
toXML(java.lang.String enclosingNamespace) |
public static final java.lang.String ELEMENT
public static final java.lang.String FORM_TYPE
public FormField(java.lang.String variable)
variable
- the variable name of the question.public FormField()
public java.lang.String getDescription()
If the question is of type FIXED then the description should remain empty.
public java.lang.String getLabel()
public java.util.List<FormField.Option> getOptions()
public boolean isRequired()
public FormField.Type getType()
FormField.Type
public java.util.List<java.lang.CharSequence> getValues()
public java.util.List<java.lang.String> getValuesAsString()
getValues()
whenever possible instead of this
method.getValues()
public java.lang.String getFirstValue()
null
.null
public java.util.Date getFirstValueAsDate() throws java.text.ParseException
null
.java.text.ParseException
- if parsing fails.public java.lang.String getVariable()
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")
public ValidateElement getValidateElement()
public void setDescription(java.lang.String description)
If the question is of type FIXED then the description should remain empty.
description
- provides extra clarification about the question.public void setLabel(java.lang.String label)
label
- the label of the question.public void setRequired(boolean required)
required
- if the question must be answered in order to complete the questionnaire.public void setValidateElement(ValidateElement validateElement)
validateElement
- the validateElement to setpublic void setType(FormField.Type type)
This method will throw an IllegalArgumentException if type is 'fixed'. To create FormFields of type 'fixed' use
FormField()
instead.
type
- an indicative of the format for the data to answer.java.lang.IllegalArgumentException
- if type is 'fixed'.FormField.Type
public void addValue(java.lang.CharSequence value)
value
- a default value or an answered value of the question.public void addValue(java.util.Date date)
addValue(CharSequence)
after the date
instance was formated.date
- the date instance to add as XEP-0082 formated string.public void addValues(java.util.List<? extends java.lang.CharSequence> newValues)
newValues
- default values or an answered values of the question.protected void resetValues()
public void addOption(FormField.Option option)
option
- a new available option for the question.public java.lang.String getElementName()
getElementName
in interface org.jivesoftware.smack.packet.NamedElement
public org.jivesoftware.smack.util.XmlStringBuilder toXML(java.lang.String enclosingNamespace)
toXML
in interface org.jivesoftware.smack.packet.Element
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object