public class BaseForm extends java.lang.Object implements Form
Fields. Once
built a Form can be used as a Map between field names and values. The methods
used to actually edit a form are specific to the form sub-class however this class
can be instantiated directly for testing.
A Form may either be used as just a collection of fields with associated validation ie as a component
of a larger composite form or may contain a set of FormAction classes to define an action to take on form submission.
| Modifier and Type | Field and Description |
|---|---|
protected ConfirmMessage |
additional_confirm |
protected Logger |
log |
protected java.util.Set<FormValidator> |
validators |
| Constructor and Description |
|---|
BaseForm(AppContext c) |
| Modifier and Type | Method and Description |
|---|---|
void |
addAction(java.lang.String name,
FormAction action)
add an FormAction to this Form
|
<I> Field |
addInput(java.lang.String key,
java.lang.String label,
Input<I> s)
Add and input to the next slot in the form
|
<I> Field |
addInput(java.lang.String key,
java.lang.String label,
java.lang.String help,
Input<I> s)
Add and input to the next slot in the form
|
void |
addValidator(FormValidator v)
Set a FormValidator to perform overall sanity check on the form.
|
void |
clear() |
boolean |
containsInput(java.lang.Class<? extends Input> c)
Check a form to see if it contains an input of a particular type.
|
java.lang.String |
diff(java.util.Map<java.lang.String,java.lang.Object> m)
Compare the values of this forms inputs with the contents of a Map
and generate a text summary;
|
FormResult |
doAction(java.lang.String name)
perform a named action on this form.
|
int |
fieldCount() |
java.lang.Object |
get(java.lang.String key)
get the value associated with a Form field.
|
FormAction |
getAction(java.lang.String name)
get a
FormAction by name. |
java.util.Set<java.lang.String> |
getActionNames()
Get an
Set of the names of the installed Actions. |
java.lang.String |
getAutoFocus()
get field for auto-focus
|
java.util.Map<java.lang.String,java.lang.Object> |
getContents()
get the contents of a form as a Map
|
AppContext |
getContext()
get the AppContext associated with this Form
|
Field |
getField(java.lang.String key)
get a Field object
|
java.util.Iterator<java.lang.String> |
getFieldIterator()
get an iterator over the field names
|
java.util.Set<java.lang.String> |
getFieldNames() |
java.lang.String |
getFormID()
get the form-ids
In HTML this is used as a prefix for the input html-ids
|
Input |
getInput(java.lang.String key)
get the Input associated with a Field
|
java.lang.Object |
getItem(java.lang.String key)
get the Item associated with a Form field.
|
Logger |
getLogger() |
java.lang.String |
getSingleActionName()
get the default action name.
|
Table<java.lang.String,java.lang.String> |
getTable()
get the form contents as a Table
|
java.util.Set<FormValidator> |
getValidators()
get the current Form validator
|
boolean |
hasActions() |
boolean |
hasField(java.lang.String key)
Does form contain specified field
|
java.util.Iterator<Field> |
iterator() |
protected <I> Field<I> |
makeField(java.lang.String key,
java.lang.String label,
Input<I> sel)
make a field appropriate for this form, this in principle could be sub-classed if we
want custom Fields, but it is usually simpler to implement all customisations in the Form sub-class.
|
ConfirmMessage |
mustConfirm(java.lang.String name)
Test if this action should be confirmed before execute
|
java.lang.Object |
put(java.lang.String key,
java.lang.Object value)
set the value associated with a form field
|
void |
removeAction(java.lang.String name)
remove a
FormAction. |
void |
removeField(java.lang.String key)
remove a field from the form
|
void |
removeValidator(FormValidator v)
Remove a
FormValidator |
void |
setAutoFocus(java.lang.String field)
set field for auto-focus
|
void |
setConfirm(java.lang.String name,
java.lang.String conf) |
void |
setContents(java.util.Map<java.lang.String,java.lang.Object> m)
set the contents of a Form from a Map
|
void |
setFormID(java.lang.String id)
Set a form-id for this form.
|
java.lang.String |
toString() |
void |
update(java.util.Map<java.lang.String,java.lang.Object> m)
modify an existing Map updating the fields represented by the Form.
|
boolean |
validate()
validate a form
This does not attempt to report details of any problem and
will return as soon as any validation condition fails.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitgetTargetStage, isComplete, isFixed, poll, setTargetStage, supportsMultiStageprotected java.util.Set<FormValidator> validators
protected Logger log
protected ConfirmMessage additional_confirm
public BaseForm(AppContext c)
public void addAction(java.lang.String name,
FormAction action)
public void removeAction(java.lang.String name)
FormFormAction.removeAction in interface Formpublic <I> Field addInput(java.lang.String key, java.lang.String label, Input<I> s)
public <I> Field addInput(java.lang.String key, java.lang.String label, java.lang.String help, Input<I> s)
public void clear()
public boolean containsInput(java.lang.Class<? extends Input> c)
containsInput in interface Formc - Class for the Input type to be testespublic FormResult doAction(java.lang.String name) throws FieldException, ActionException
doAction in interface Formname - String name of actionFieldExceptionActionExceptionpublic FormAction getAction(java.lang.String name)
FormFormAction by name.public java.lang.Object get(java.lang.String key)
public java.lang.Object getItem(java.lang.String key)
Formpublic java.util.Set<java.lang.String> getActionNames()
FormSet of the names of the installed Actions.getActionNames in interface Formpublic java.lang.String getSingleActionName()
public boolean hasActions()
public int fieldCount()
public void setConfirm(java.lang.String name,
java.lang.String conf)
setConfirm in interface Formpublic java.util.Map<java.lang.String,java.lang.Object> getContents()
getContents in interface Formpublic AppContext getContext()
getContext in interface Contexedpublic Field getField(java.lang.String key)
public final boolean hasField(java.lang.String key)
Formpublic java.util.Iterator<java.lang.String> getFieldIterator()
getFieldIterator in interface Formpublic java.util.Set<java.lang.String> getFieldNames()
public Input getInput(java.lang.String key)
public Logger getLogger()
public Table<java.lang.String,java.lang.String> getTable()
public final java.util.Set<FormValidator> getValidators()
getValidators in interface Formprotected <I> Field<I> makeField(java.lang.String key, java.lang.String label, Input<I> sel)
key - label - sel - public ConfirmMessage mustConfirm(java.lang.String name) throws ActionException
name - ActionExceptionpublic java.lang.Object put(java.lang.String key,
java.lang.Object value)
public void removeField(java.lang.String key)
removeField in interface Formkey - public void setContents(java.util.Map<java.lang.String,java.lang.Object> m)
setContents in interface Formm - Map of valuespublic final void addValidator(FormValidator v)
addValidator in interface Formv - The FormValidator to set.public final void removeValidator(FormValidator v)
FormFormValidatorremoveValidator in interface Formpublic void update(java.util.Map<java.lang.String,java.lang.Object> m)
public java.lang.String diff(java.util.Map<java.lang.String,java.lang.Object> m)
public final boolean validate()
validate in interface FormValidateExceptionpublic java.util.Iterator<Field> iterator()
iterator in interface java.lang.Iterable<Field>public java.lang.String toString()
toString in class java.lang.Objectpublic void setFormID(java.lang.String id)
Formpublic java.lang.String getFormID()
Formpublic void setAutoFocus(java.lang.String field)
FormsetAutoFocus in interface Formpublic java.lang.String getAutoFocus()
FormgetAutoFocus in interface Form