public class Form extends Object
Constructor and Description |
---|
Form(DataForm.Type type)
Creates a new Form of a given type from scratch.
|
Form(DataForm dataForm)
Creates a new Form that will wrap an existing DataForm.
|
Modifier and Type | Method and Description |
---|---|
void |
addField(FormField field)
Adds a new field to complete as part of the form.
|
Form |
createAnswerForm()
Returns a new Form to submit the completed values.
|
DataForm |
getDataFormToSend()
Returns a DataForm that serves to send this Form to the server.
|
FormField |
getField(String variable)
Returns the field of the form whose variable matches the specified variable.
|
List<FormField> |
getFields()
Returns a List of the fields that are part of the form.
|
static Form |
getFormFrom(Stanza packet)
Returns a new ReportedData if the stanza(/packet) is used for gathering data and includes an
extension that matches the elementName and namespace "x","jabber:x:data".
|
String |
getInstructions()
Returns the instructions that explain how to fill out the form and what the form is about.
|
String |
getTitle()
Returns the description of the data.
|
DataForm.Type |
getType()
Returns the meaning of the data within the context.
|
void |
setAnswer(String variable,
boolean value)
Sets a new boolean value to a given form's field.
|
void |
setAnswer(String variable,
double value)
Sets a new double value to a given form's field.
|
void |
setAnswer(String variable,
float value)
Sets a new float value to a given form's field.
|
void |
setAnswer(String variable,
int value)
Sets a new int value to a given form's field.
|
void |
setAnswer(String variable,
List<String> values)
Sets a new values to a given form's field.
|
void |
setAnswer(String variable,
long value)
Sets a new long value to a given form's field.
|
void |
setAnswer(String variable,
String value)
Sets a new String value to a given form's field.
|
void |
setDefaultAnswer(String variable)
Sets the default value as the value of a given form's field.
|
void |
setInstructions(String instructions)
Sets instructions that explain how to fill out the form and what the form is about.
|
void |
setTitle(String title)
Sets the description of the data.
|
public Form(DataForm dataForm)
dataForm
- the data form used for gathering data.public Form(DataForm.Type type)
type
- the form's type (e.g. form, submit,cancel,result).public static Form getFormFrom(Stanza packet)
packet
- the stanza(/packet) used for gathering data.public void addField(FormField field)
field
- the field to complete.public void setAnswer(String variable, String value)
If the value to set to the field is not a basic type (e.g. String, boolean, int, etc.) you can use this message where the String value is the String representation of the object.
variable
- the variable name that was completed.value
- the String value that was answered.IllegalStateException
- if the form is not of type "submit".IllegalArgumentException
- if the form does not include the specified variable or
if the answer type does not correspond with the field type..public void setAnswer(String variable, int value)
variable
- the variable name that was completed.value
- the int value that was answered.IllegalStateException
- if the form is not of type "submit".IllegalArgumentException
- if the form does not include the specified variable or
if the answer type does not correspond with the field type.public void setAnswer(String variable, long value)
variable
- the variable name that was completed.value
- the long value that was answered.IllegalStateException
- if the form is not of type "submit".IllegalArgumentException
- if the form does not include the specified variable or
if the answer type does not correspond with the field type.public void setAnswer(String variable, float value)
variable
- the variable name that was completed.value
- the float value that was answered.IllegalStateException
- if the form is not of type "submit".IllegalArgumentException
- if the form does not include the specified variable or
if the answer type does not correspond with the field type.public void setAnswer(String variable, double value)
variable
- the variable name that was completed.value
- the double value that was answered.IllegalStateException
- if the form is not of type "submit".IllegalArgumentException
- if the form does not include the specified variable or
if the answer type does not correspond with the field type.public void setAnswer(String variable, boolean value)
variable
- the variable name that was completed.value
- the boolean value that was answered.IllegalStateException
- if the form is not of type "submit".IllegalArgumentException
- if the form does not include the specified variable or
if the answer type does not correspond with the field type.public void setAnswer(String variable, List<String> values)
The Objects contained in the List could be of any type. The String representation of them (i.e. #toString) will be actually used when sending the answer to the server.
variable
- the variable that was completed.values
- the values that were answered.IllegalStateException
- if the form is not of type "submit".IllegalArgumentException
- if the form does not include the specified variable.public void setDefaultAnswer(String variable)
variable
- the variable to complete with its default value.IllegalStateException
- if the form is not of type "submit".IllegalArgumentException
- if the form does not include the specified variable.public List<FormField> getFields()
public FormField getField(String variable)
variable
- the variable to look for in the form fields.public String getInstructions()
public String getTitle()