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 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.
|
boolean |
hasField(String variable)
Check if a field with the given variable exists.
|
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<? extends CharSequence> 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 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<? extends CharSequence> 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 boolean hasField(String variable)
variable
- the variable to check for.public String getInstructions()
public String getTitle()
public DataForm.Type getType()
public void setInstructions(String instructions)
instructions
- instructions that explain how to fill out the form.public void setTitle(String title)
title
- description of the data.public DataForm getDataFormToSend()
public Form createAnswerForm()
The reason why the fields with variables are included in the new form is to provide a model for binding with any UI. This means that the UIs will use the original form (of type "form") to learn how to render the form, but the UIs will bind the fields to the form of type submit.