1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-26 22:12:05 +01:00

Added #setDefaultAnswer(String) to set the default value as the current value of a given field

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2393 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Gaston Dombiak 2004-10-22 20:54:53 +00:00 committed by gaston
parent b7bf4ad782
commit ef0d5c8fb8

View file

@ -347,6 +347,34 @@ public class Form {
} }
} }
/**
* Sets the default value as the value of a given form's field. The field whose variable matches
* the requested variable will be completed with its default value. If no field could be found
* for the specified variable then an exception will be raised.
*
* @param variable the variable to complete with its default value.
* @throws IllegalStateException if the form is not of type "submit".
* @throws IllegalArgumentException if the form does not include the specified variable.
*/
public void setDefaultAnswer(String variable) {
if (!isSubmitType()) {
throw new IllegalStateException("Cannot set an answer if the form is not of type " +
"\"submit\"");
}
FormField field = getField(variable);
if (field != null) {
// Clear the old values
field.resetValues();
// Set the default value
for (Iterator it = field.getValues(); it.hasNext();) {
field.addValue((String) it.next());
}
}
else {
throw new IllegalArgumentException("Couldn't find a field for the specified variable.");
}
}
/** /**
* Returns an Iterator for the fields that are part of the form. * Returns an Iterator for the fields that are part of the form.
* *