ItEr26S03ContornaItEr25S03: Checking at WorkerCRUDController that there are no invalid inputs before saving

This commit is contained in:
Óscar González Fernández 2009-09-16 17:30:46 +02:00
parent f6155662cc
commit b1bb380e96
3 changed files with 46 additions and 2 deletions

View file

@ -0,0 +1,40 @@
package org.navalplanner.web.common;
import java.util.List;
import org.zkoss.zk.ui.Component;
import org.zkoss.zul.impl.api.InputElement;
/**
* Class for checking the inexistence of invalid values
* @author Óscar González Fernández <ogonzalez@igalia.com>
*/
public class InvalidInputsChecker {
public static boolean thereAreInvalidInputsOn(Component component) {
if (isInvalid(component)) {
return true;
}
List<Component> children = component.getChildren();
for (Component child : children) {
if (isInvalid(child)) {
return true;
}
if (thereAreInvalidInputsOn(child)) {
return true;
}
}
return false;
}
private static boolean isInvalid(Component child) {
if (child instanceof InputElement) {
InputElement input = (InputElement) child;
if (!input.isValid()) {
return true;
}
}
return false;
}
}

View file

@ -2,6 +2,7 @@ package org.navalplanner.web.resources.worker;
import static org.navalplanner.web.I18nHelper._;
import static org.navalplanner.web.common.ConcurrentModificationDetector.addAutomaticHandlingOfConcurrentModification;
import static org.navalplanner.web.common.InvalidInputsChecker.thereAreInvalidInputsOn;
import java.util.Date;
import java.util.List;
@ -113,6 +114,9 @@ public class WorkerCRUDController extends GenericForwardComposer implements
}
public void save() {
if (thereAreInvalidInputsOn(getCurrentWindow())) {
return;
}
try {
if (baseCalendarEditionController != null) {
baseCalendarEditionController.save();

View file

@ -20,12 +20,12 @@
<row>
<label value="${i18n:_('First name')}" />
<textbox
value="@{controller.worker.firstName}" />
value="@{controller.worker.firstName}" constraint="no empty"/>
</row>
<row>
<label value="${i18n:_('Last name')}" />
<textbox
value="@{controller.worker.surname}" />
value="@{controller.worker.surname}" constraint="no empty" />
</row>
<row>
<label value="${i18n:_('NIF')}" />