@Validatable
class ServerParameter {
@Bindable String serverName
@Bindable int port
@Bindable String displayName
def beforeValidation = {
setDisplayName "${serverName}:${port}"
}
static constraints = {
serverName(nullable: false, blank: false)
port(range: 0..65535)
displayName(nullable: false, blank: false)
}
}
@Validatable
class ProtocolSpecificServerParameter extends ServerParameter{
@Bindable String protocol
def beforeValidation = {
setDisplayName "${protocol}://${serverName}:${port}"
}
static constraints = {
protocol(blank: false, nullable: false)
}
}
In the above example, the ProtocolSpecificServerParameter will not only inherent ServerParameter's serverName and port fields but also their associated constraints. The only resitration you need to be aware of is if the parent constraint generates error for a certain condition then the overriding child constraint has to generate error as well. In other words, validation plugin does not allow error hiding by using constraint override in the child class, similar to the method exception handling during inheritance within Java.
No comments:
Post a Comment