| Method from org.apache.commons.validator.Form Detail: |
public void addField(Field f) {
this.lFields.add(f);
this.hFields.put(f.getKey(), f);
}
|
public boolean containsField(String fieldName) {
return this.hFields.containsKey(fieldName);
}
Returns true if this Form contains a Field with the given name. |
public String getExtends() {
return inherit;
}
Gets the name/key of the parent set of validation rules. |
public Field getField(String fieldName) {
return (Field) this.hFields.get(fieldName);
}
Returns the Field with the given name or null if this Form has no such
field. |
protected Map getFieldMap() {
return hFields;
}
Returns a Map of String field keys to Field objects. |
public List getFields() {
return Collections.unmodifiableList(lFields);
}
A List of Fields is returned as an unmodifiable
List. |
public String getName() {
return name;
}
Gets the name/key of the set of validation rules. |
public boolean isExtending() {
return inherit != null;
}
|
public boolean isProcessed() {
return processed;
}
Whether or not the this Form was processed for replacing
variables in strings with their values. |
protected void merge(Form depends) {
List templFields = new ArrayList();
Map temphFields = new FastHashMap();
Iterator dependsIt = depends.getFields().iterator();
while (dependsIt.hasNext()) {
Field defaultField = (Field) dependsIt.next();
if (defaultField != null) {
String fieldKey = defaultField.getKey();
if (!this.containsField(fieldKey)) {
templFields.add(defaultField);
temphFields.put(fieldKey, defaultField);
}
else {
Field old = getField(fieldKey);
hFields.remove(fieldKey);
lFields.remove(old);
templFields.add(old);
temphFields.put(fieldKey, old);
}
}
}
lFields.addAll(0, templFields);
hFields.putAll(temphFields);
}
Merges the given form into this one. For any field in depends
not present in this form, include it. depends has precedence
in the way the fields are ordered. |
protected void process(Map globalConstants,
Map constants,
Map forms) {
if (isProcessed()) {
return;
}
int n = 0;//we want the fields from its parent first
if (isExtending()) {
Form parent = (Form) forms.get(inherit);
if (parent != null) {
if (!parent.isProcessed()) {
//we want to go all the way up the tree
parent.process(constants, globalConstants, forms);
}
for (Iterator i = parent.getFields().iterator(); i.hasNext(); ) {
Field f = (Field) i.next();
//we want to be able to override any fields we like
if (hFields.get(f.getKey()) == null) {
lFields.add(n, f);
hFields.put(f.getKey(), f);
n++;
}
}
}
}
hFields.setFast(true);
//no need to reprocess parent's fields, we iterate from 'n'
for (Iterator i = lFields.listIterator(n); i.hasNext(); ) {
Field f = (Field) i.next();
f.process(globalConstants, constants);
}
processed = true;
}
Processes all of the Form's Fields. |
public void setExtends(String inherit) {
this.inherit = inherit;
}
Sets the name/key of the parent set of validation rules. |
public void setName(String name) {
this.name = name;
}
Sets the name/key of the set of validation rules. |
public String toString() {
StringBuffer results = new StringBuffer();
results.append("Form: ");
results.append(name);
results.append("\n");
for (Iterator i = lFields.iterator(); i.hasNext(); ) {
results.append("\tField: \n");
results.append(i.next());
results.append("\n");
}
return results.toString();
}
Returns a string representation of the object. |
ValidatorResults validate(Map params,
Map actions,
int page) throws ValidatorException {
return validate(params, actions, page, null);
}
Validate all Fields in this Form on the given page and below. |
ValidatorResults validate(Map params,
Map actions,
int page,
String fieldName) throws ValidatorException {
ValidatorResults results = new ValidatorResults();
params.put(Validator.VALIDATOR_RESULTS_PARAM, results);
// Only validate a single field if specified
if (fieldName != null) {
Field field = (Field) this.hFields.get(fieldName);
if (field == null) {
throw new ValidatorException("Unknown field "+fieldName+" in form "+getName());
}
params.put(Validator.FIELD_PARAM, field);
if (field.getPage() < = page) {
results.merge(field.validate(params, actions));
}
} else {
Iterator fields = this.lFields.iterator();
while (fields.hasNext()) {
Field field = (Field) fields.next();
params.put(Validator.FIELD_PARAM, field);
if (field.getPage() < = page) {
results.merge(field.validate(params, actions));
}
}
}
return results;
}
Validate all Fields in this Form on the given page and below. |