public class Form extends Object
Modifier and Type | Field and Description |
---|---|
static String |
TYPE_CANCEL |
static String |
TYPE_FORM |
static String |
TYPE_RESULT |
static String |
TYPE_SUBMIT |
Constructor and Description |
---|
Form(DataForm dataForm)
Creates a new Form that will wrap an existing DataForm.
|
Form(String type)
Creates a new Form of a given type from scratch.
|
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(Packet packet)
Returns a new ReportedData if the 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.
|
String |
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 static final String TYPE_FORM
public static final String TYPE_SUBMIT
public static final String TYPE_CANCEL
public static final String TYPE_RESULT
public Form(DataForm dataForm)
dataForm
- the data form used for gathering data.public Form(String type)
Possible form types are:
type
- the form's type (e.g. form, submit,cancel,result).public static Form getFormFrom(Packet packet)
packet
- the 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()
public String getType()
Possible form types are:
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.