net.sf.easyweb4j.model
Class Model

java.lang.Object
  extended by net.sf.easyweb4j.model.Model
All Implemented Interfaces:
Serializable

public abstract class Model
extends Object
implements Serializable

Super class to be extended by all application's models. It provides various methods to simplify creating a well-encapsulated domain model.

Author:
Chandra Sekar S
See Also:
Serialized Form

Constructor Summary
Model()
           
 
Method Summary
 void addError(String property, String errorKey)
          Adds an error key for the specified property.
 void clearErrors()
          Clears all the errors on the model's properties.
 Map<String,ErrorDetail> getErrors()
          Returns a map of all errors on the properties of the model with the name of the properties as the key.
 boolean hasErrorOn(String property)
          Determines whether there is any error in the value of the property with the given name in the model.
 boolean isValid()
          Determines whether there are any errors present in the values of the model's properties.
protected  void validate()
          This method may be overridden by applications' models to validate the state of the model.
protected  void validateRequired(String property, Collection<?> value)
          Checks if the field isn't null and size of the collection is greater than zero.
protected  void validateRequired(String property, Object value)
          Checks if the field isn't null.
protected  void validateRequired(String property, String value)
          Checks if the field isn't null and length of the field is greater than zero after trimming white spaces.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Model

public Model()
Method Detail

addError

public void addError(String property,
                     String errorKey)
Adds an error key for the specified property.

Parameters:
property - The property for which the error key is to be added.
errorKey - The error message key to be added.

clearErrors

public void clearErrors()
Clears all the errors on the model's properties.


hasErrorOn

public boolean hasErrorOn(String property)
Determines whether there is any error in the value of the property with the given name in the model.

Parameters:
property - The property whose errors are to be checked.
Returns:
true if there is an error false otherwise.

isValid

public boolean isValid()
Determines whether there are any errors present in the values of the model's properties.

Returns:
true if there are no errors, false otherwise.

getErrors

public Map<String,ErrorDetail> getErrors()
Returns a map of all errors on the properties of the model with the name of the properties as the key.

Returns:
A map of all current errors.

validate

protected void validate()
This method may be overridden by applications' models to validate the state of the model.


validateRequired

protected void validateRequired(String property,
                                Object value)
Checks if the field isn't null. If null, it adds an error on the given property with the error key property + ".required".

Parameters:
property - The name of the property to be validated.
value - The current value of the property.

validateRequired

protected void validateRequired(String property,
                                String value)
Checks if the field isn't null and length of the field is greater than zero after trimming white spaces. If null or empty, it adds an error on the given property with the error key property + ".required" .

Parameters:
property - The name of the property to be validated.
value - The current value of the property.

validateRequired

protected void validateRequired(String property,
                                Collection<?> value)
Checks if the field isn't null and size of the collection is greater than zero. If null or empty, it adds an error on the given property with the error key property + ".required".

Parameters:
property - The name of the property to be validated.
value - The current value of the property.


Copyright © 2009-2010 Chandra Sekar S. All Rights Reserved.