|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.codehaus.groovy.grails.validation.ConstrainedProperty
public class ConstrainedProperty
Provides the ability to set contraints against a properties of a class. Constraints can either be set via the property setters or via the
applyConstraint(String constraintName, Object constrainingValue)in combination with a constraint constant. Example:
...
ConstrainedProperty cp = new ConstrainedProperty(owningClass, propertyName, propertyType);
if(cp.supportsConstraint( ConstrainedProperty.EMAIL_CONSTRAINT ) ) {
cp.applyConstraint( ConstrainedProperty.EMAIL_CONSTRAINT, new Boolean(true) );
}
Alternatively constraints can be applied directly using the java bean getters/setters if a static (as oposed to dynamic)
approach to constraint creation is possible:
cp.setEmail(true)
Constructor Summary | |
---|---|
ConstrainedProperty(Class clazz,
String propertyName,
Class propertyType)
Constructs a new ConstrainedProperty for the given arguments |
Method Summary | |
---|---|
void |
addMetaConstraint(String name,
Object value)
Adds a meta constraints which is a non-validating informational constraint |
void |
applyConstraint(String constraintName,
Object constrainingValue)
Applies a constraint for the specified name and consraint value |
Constraint |
getAppliedConstraint(String name)
Obtains an applied constraint by name |
Collection |
getAppliedConstraints()
|
Map |
getAttributes()
|
String |
getFormat()
|
List |
getInList()
|
String |
getMatches()
|
Comparable |
getMax()
|
Integer |
getMaxSize()
|
Object |
getMetaConstraintValue(String name)
Obtains the value of the named meta constraint |
Comparable |
getMin()
|
Integer |
getMinSize()
|
Object |
getNotEqual()
|
int |
getOrder()
|
String |
getPropertyName()
|
Class |
getPropertyType()
|
groovy.lang.Range |
getRange()
|
Integer |
getScale()
|
groovy.lang.Range |
getSize()
|
String |
getWidget()
|
boolean |
hasAppliedConstraint(String constraintName)
|
static boolean |
hasRegisteredConstraint(String constraintName)
|
boolean |
isBlank()
|
boolean |
isCreditCard()
|
boolean |
isDisplay()
|
boolean |
isEditable()
|
boolean |
isEmail()
|
boolean |
isNullable()
|
boolean |
isPassword()
|
boolean |
isUrl()
|
static void |
registerNewConstraint(String name,
Class constraintClass)
|
static void |
registerNewConstraint(String name,
ConstraintFactory factory)
|
void |
setAttributes(Map attributes)
|
void |
setBlank(boolean blank)
|
void |
setCreditCard(boolean creditCard)
|
void |
setDisplay(boolean display)
|
void |
setEditable(boolean editable)
|
void |
setEmail(boolean email)
|
void |
setFormat(String format)
|
void |
setInList(List inList)
|
void |
setMatches(String regex)
|
void |
setMax(Comparable max)
|
void |
setMaxSize(Integer maxSize)
|
void |
setMessageSource(MessageSource source)
The message source used to evaluate error messages |
void |
setMin(Comparable min)
|
void |
setMinSize(Integer minSize)
|
void |
setNotEqual(Object notEqual)
|
void |
setNullable(boolean nullable)
|
void |
setOrder(int order)
|
void |
setPassword(boolean password)
|
void |
setPropertyName(String propertyName)
|
void |
setRange(groovy.lang.Range range)
|
void |
setSize(groovy.lang.Range size)
|
void |
setUrl(boolean url)
|
void |
setWidget(String widget)
|
boolean |
supportsContraint(String constraintName)
Checks with this ConstraintedProperty instance supports applying the specified constraint |
String |
toString()
|
void |
validate(Object target,
Object propertyValue,
Errors errors)
Validate this constrainted property against specified property value |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
static final String DEFAULT_NULL_MESSAGE_CODE
static final String DEFAULT_INVALID_MIN_SIZE_MESSAGE_CODE
static final String DEFAULT_INVALID_MAX_SIZE_MESSAGE_CODE
static final String DEFAULT_NOT_EQUAL_MESSAGE_CODE
static final String DEFAULT_INVALID_MIN_MESSAGE_CODE
static final String DEFAULT_INVALID_MAX_MESSAGE_CODE
static final String DEFAULT_INVALID_SIZE_MESSAGE_CODE
static final String DEFAULT_NOT_INLIST_MESSAGE_CODE
static final String DEFAULT_INVALID_RANGE_MESSAGE_CODE
static final String DEFAULT_INVALID_EMAIL_MESSAGE_CODE
static final String DEFAULT_INVALID_CREDIT_CARD_MESSAGE_CODE
static final String DEFAULT_INVALID_URL_MESSAGE_CODE
static final String DEFAULT_INVALID_VALIDATOR_MESSAGE_CODE
static final String DEFAULT_DOESNT_MATCH_MESSAGE_CODE
static final String DEFAULT_BLANK_MESSAGE_CODE
protected static final ResourceBundle bundle
public static final String CREDIT_CARD_CONSTRAINT
public static final String EMAIL_CONSTRAINT
public static final String BLANK_CONSTRAINT
public static final String RANGE_CONSTRAINT
public static final String IN_LIST_CONSTRAINT
public static final String URL_CONSTRAINT
public static final String MATCHES_CONSTRAINT
public static final String SIZE_CONSTRAINT
public static final String MIN_CONSTRAINT
public static final String MAX_CONSTRAINT
public static final String MAX_SIZE_CONSTRAINT
public static final String MIN_SIZE_CONSTRAINT
public static final String SCALE_CONSTRAINT
public static final String NOT_EQUAL_CONSTRAINT
public static final String NULLABLE_CONSTRAINT
public static final String VALIDATOR_CONSTRAINT
protected static final String INVALID_SUFFIX
protected static final String EXCEEDED_SUFFIX
protected static final String NOTMET_SUFFIX
protected static final String NOT_PREFIX
protected static final String TOOBIG_SUFFIX
protected static final String TOOLONG_SUFFIX
protected static final String TOOSMALL_SUFFIX
protected static final String TOOSHORT_SUFFIX
protected static Map constraints
protected static final Map DEFAULT_MESSAGES
protected static final org.apache.commons.logging.Log LOG
protected String propertyName
protected Class propertyType
protected Map appliedConstraints
protected Class owningClass
protected MessageSource messageSource
Constructor Detail |
---|
public ConstrainedProperty(Class clazz, String propertyName, Class propertyType)
clazz
- The owning classpropertyName
- The name of the propertypropertyType
- The property typeMethod Detail |
---|
public static void registerNewConstraint(String name, Class constraintClass)
public static void registerNewConstraint(String name, ConstraintFactory factory)
public static boolean hasRegisteredConstraint(String constraintName)
public Collection getAppliedConstraints()
public Constraint getAppliedConstraint(String name)
name
- The name of the constraint
public boolean hasAppliedConstraint(String constraintName)
constraintName
- The name of the constraint to check
public Class getPropertyType()
public Comparable getMax()
public void setMax(Comparable max)
max
- The max to set.public Comparable getMin()
public void setMin(Comparable min)
min
- The min to set.public List getInList()
public void setInList(List inList)
inList
- The inList to set.public groovy.lang.Range getRange()
public void setRange(groovy.lang.Range range)
range
- The range to set.public Integer getScale()
public groovy.lang.Range getSize()
public void setSize(groovy.lang.Range size)
size
- The size to set.public boolean isBlank()
public void setBlank(boolean blank)
blank
- The blank to set.public boolean isEmail()
public void setEmail(boolean email)
email
- The email to set.public boolean isCreditCard()
public void setCreditCard(boolean creditCard)
creditCard
- The creditCard to set.public String getMatches()
public void setMatches(String regex)
regex
- The matches to set.public Object getNotEqual()
public Integer getMaxSize()
public void setMaxSize(Integer maxSize)
maxSize
- The maxSize to set.public Integer getMinSize()
public void setMinSize(Integer minSize)
minSize
- The minLength to set.public void setNotEqual(Object notEqual)
notEqual
- The notEqual to set.public boolean isNullable()
public void setNullable(boolean nullable)
nullable
- The nullable to set.public String getPropertyName()
public void setPropertyName(String propertyName)
propertyName
- The propertyName to set.public boolean isUrl()
public void setUrl(boolean url)
url
- The url to set.public boolean isDisplay()
public void setDisplay(boolean display)
display
- The display to set.public boolean isEditable()
public void setEditable(boolean editable)
editable
- The editable to set.public int getOrder()
public void setOrder(int order)
order
- The order to set.public String getFormat()
public void setFormat(String format)
public boolean isPassword()
public void setPassword(boolean password)
public Map getAttributes()
public void setAttributes(Map attributes)
public String getWidget()
public void setWidget(String widget)
public void setMessageSource(MessageSource source)
source
- The MessageSource instance to use to resolve messagespublic void validate(Object target, Object propertyValue, Errors errors)
target
- The target object to validatepropertyValue
- The value of the property to validateerrors
- The Errors instances to report errors topublic boolean supportsContraint(String constraintName)
constraintName
- The name of the constraint
public void applyConstraint(String constraintName, Object constrainingValue)
constraintName
- The name of the constraintconstrainingValue
- The constraining value
ConstraintException
- Thrown when the specified constraint is not supported by this ConstrainedProperty. Use supportsContraint(String constraintName)
to check before callingpublic String toString()
toString
in class Object
public void addMetaConstraint(String name, Object value)
name
- The name of the constraintvalue
- The valuepublic Object getMetaConstraintValue(String name)
name
- The name of the constraint
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |