ItEr35S15CUAdministracionCategoriaCosteItEr34S15: implemented null validation

TODO: unique constraints produce an Exception; it has to be transformed into
a ValidationException to be treated correctly by the web application.
This commit is contained in:
Jacobo Aragunde Pérez 2009-12-02 20:58:23 +01:00 committed by Javier Moran Rua
parent 4b6ac2bbb2
commit c37fba6fa7
2 changed files with 41 additions and 7 deletions

View file

@ -33,7 +33,10 @@ import org.navalplanner.web.common.MessagesForUser;
import org.navalplanner.web.common.OnlyOneVisible;
import org.navalplanner.web.common.Util;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.WrongValueException;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zul.api.Checkbox;
import org.zkoss.zul.api.Textbox;
import org.zkoss.zul.api.Window;
/**
@ -56,11 +59,20 @@ public class TypeOfWorkHoursCRUDController extends GenericForwardComposer implem
private Component messagesContainer;
private Textbox code;
private Textbox name;
private Textbox defaultPrice;
private Checkbox enabled;
@Override
public void doAfterCompose(Component comp) throws Exception {
super.doAfterCompose(comp);
comp.setVariable("controller", this, true);
messagesForUser = new MessagesForUser(messagesContainer);
code = (Textbox) createWindow.getFellowIfAny("code");
name = (Textbox) createWindow.getFellowIfAny("name");
defaultPrice = (Textbox) createWindow.getFellowIfAny("defaultPrice");
enabled = (Checkbox) createWindow.getFellowIfAny("enabled");
getVisibility().showOnly(listWindow);
}
@ -100,17 +112,37 @@ public class TypeOfWorkHoursCRUDController extends GenericForwardComposer implem
}
public boolean save() {
if(!validate()) {
return false;
}
try {
typeOfWorkHoursModel.confirmSave();
messagesForUser.showMessage(Level.INFO,
_("Type of work hours saved"));
return true;
} catch (ValidationException e) {
//TODO: implement validation errors
messagesForUser.showMessage(Level.ERROR, e.getMessage());
}
return false;
}
/* validates the constraints of the elements in ZK */
private boolean validate() {
try {
//we 'touch' the attributes in the interface
//if any of their constraints is active, they
//will throw an exception
code.getValue();
name.getValue();
defaultPrice.getValue();
enabled.isChecked();
return true;
}
catch (WrongValueException e) {
return false;
}
}
public List<TypeOfWorkHours> getTypesOfWorkHours() {
return typeOfWorkHoursModel.getTypesOfWorkHours();
}

View file

@ -39,21 +39,23 @@
<label
value="${i18n:_('Code')}:" />
<textbox id="code"
value="@{controller.typeOfWorkHours.code}" width="300px" />
value="@{controller.typeOfWorkHours.code}" width="300px"
constraint="no empty:${i18n:_('cannot be null or empty')}"/>
</row>
<row>
<label value="${i18n:_('Name')}:" />
<textbox
value="@{controller.typeOfWorkHours.name}" width="300px" />
<textbox id="name"
value="@{controller.typeOfWorkHours.name}" width="300px"
constraint="no empty:${i18n:_('cannot be null or empty')}"/>
</row>
<row>
<row>
<label value="${i18n:_('Default price')}:" />
<textbox
<textbox id="defaultPrice"
value="@{controller.typeOfWorkHours.defaultPrice}" width="300px" />
</row>
<row>
<label value="${i18n:_('Enabled')}:" />
<checkbox
<checkbox id="enabled"
checked="@{controller.typeOfWorkHours.Enabled}" width="300px" />
</row>
</rows>