Re-using GORM Validations
class Product {
String name
static constraints = {
name(blank: false, minSize: 2, maxSize: 255)
}
}Product product = new Product()
product.name = "iPhone 7"
product.save()
FormLayout form = new FormLayout()
FieldGroup binder = new FieldGroup(new BeanItem(product))
TextField txnName = binder.buildAndBind("Name", "name")
txnName.setNullRepresentation("")
def constraints = Product.constraints
def name = constraints.name
int minSize = name.minSize
int maxSize = name.maxSize
boolean blank = name.blank
StringLengthValidator validator = new StringLengthValidator("Validation failed", minSize, maxSize, blank)
txnName.addValidator(validator)
form.addComponent(txnName)Last updated