joi, 26 februarie 2015

[OmniFaces utilities (2.0)] Validate if the given component has no children


[OmniFaces utilities] The validateHasNoChildren() method validates if the given component has no children.

Method:
Basically, this method is a simple shortcut for UIComponent#getChildCount(). In addition, when the verified component has children, this method will throw an IllegalArgumentException exception with a custom message that contains a comma separated list of child's types.

Usage:
We can easily use this method in a custom validator, component, managed bean etc. Per example, you can check if a form has children:

try {
    Components.validateHasNoChildren(myform);
} catch (IllegalArgumentException e) {
    System.out.println("This form has children !" + e.getMessage());
}

A possible exception message will be:

Niciun comentariu:

Trimiteți un comentariu