/**
*
* <p>
*
*
* @param parent
*
* @param inputs
*/
private static void searchInputs(Component parent, List<InputElement> inputs) {
if (parent instanceof InputElement) {
inputs.add((InputElement) parent);
return;
}
List<Component> children = (List<Component>) parent.getChildren();
if (children == null || children.size() < 1)
return;
for (Component c : children) {
searchInputs(c, inputs);
}
}
/**
*
* <p>
* {@link InputElement} true, Bandbox, Combobox, Datebox,
* Decimalbox, Doublebox, FormatInputElement, Intbox, Longbox,
* NumberInputElement, Spinner, Textbox, Timebox
*
* @param comp
* @return
*/
public static boolean isInputElement(Component comp) {
return comp instanceof InputElement;
}
/**
*
* <p>
* {@link InputElement#setConstraint(String)}
* constraint , , <textbox
* constraint="no empty"/>constraint
* <p>
* ,
*
* @param form
*
*
* @param showError
*
* @return true, false
*/
public static boolean isValidForm(Component form, boolean showError) {
if (form == null) {
return true;
}
List<InputElement> inputs = new ArrayList<InputElement>();
searchInputs(form, inputs);
boolean valid = true;
for (InputElement elem : inputs) {
if (!elem.isValid()) {
if (showError) {
elem.getText();
}
valid = false;
}
}
return valid;
}
/**
*
*
* <p>
* {@link InputElement#setConstraint(String)}
* constraint , , <textbox
* constraint="no empty"/>constraint
* <p>
* ,
*
* @param form
*
*
* @return true, false
*/
public static boolean isValidForm(Component form) {
if (form == null) {
return true;
}
List<InputElement> inputs = new ArrayList<InputElement>();
searchInputs(form, inputs);
boolean valid = true;
for (InputElement elem : inputs) {
if (!elem.isValid()) {
elem.getText();
valid = false;
}
}
return valid;
}