[Bug #1248] Added extra validators when saving order

Check that it's not empty and only raise exception if it's not the name of the
same project being saved

FEA: ItEr75S04BugFixing
This commit is contained in:
Lorenzo Tilve Álvaro 2011-11-10 18:03:50 +01:00
parent 16dde59dde
commit 35c35480b3
2 changed files with 45 additions and 26 deletions

View file

@ -1481,30 +1481,51 @@ public class OrderCRUDController extends GenericForwardComposer {
}
}
public void chekValidProjectName(Textbox textbox) {
try {
Order found = orderDAO.findByNameAnotherTransaction(textbox
.getValue());
if ((found != null) && (!found.getId().equals(getOrder().getId()))) {
throw new WrongValueException(textbox,
_("project name already being used"));
public Constraint chekValidProjectName() {
return new Constraint() {
@Override
public void validate(Component comp, Object value)
throws WrongValueException {
if (StringUtils.isBlank((String) value)) {
throw new WrongValueException(comp,
_("cannot be null or empty"));
}
try {
Order found = orderDAO
.findByNameAnotherTransaction((String) value);
if (!found.getId().equals(getOrder().getId())) {
throw new WrongValueException(comp,
_("project name already being used"));
}
} catch (InstanceNotFoundException e) {
return;
}
}
} catch (InstanceNotFoundException e) {
return;
}
};
}
public void chekValidProjectCode(Textbox textbox) {
try {
Order found = orderDAO.findByCodeAnotherTransaction(textbox
.getValue());
if ((found != null) && (!found.getId().equals(getOrder().getId()))) {
throw new WrongValueException(textbox,
_("code already being used"));
}
} catch (InstanceNotFoundException e) {
return;
}
}
public Constraint chekValidProjectCode() {
return new Constraint() {
@Override
public void validate(Component comp, Object value)
throws WrongValueException {
if (StringUtils.isBlank((String) value)) {
throw new WrongValueException(comp,
_("cannot be null or empty"));
}
try {
Order found = orderDAO
.findByCodeAnotherTransaction((String) value);
if (!found.getId().equals(getOrder().getId())) {
throw new WrongValueException(comp,
_("project code already being used"));
}
} catch (InstanceNotFoundException e) {
return;
}
}
};
}
}

View file

@ -71,16 +71,14 @@
<row>
<label value="${i18n:_('Name')}" />
<textbox value="@{controller.order.name}" width="500px"
constraint="no empty:${i18n:_('cannot be null or empty')}"
onBlur="controller.chekValidProjectName(self)"/>
constraint="@{controller.chekValidProjectName}" />
</row>
<row>
<label value="${i18n:_('Code')}" />
<hbox>
<textbox value="@{controller.order.code}" width="250px"
disabled="@{controller.codeAutogenerated}"
constraint="no empty:${i18n:_('cannot be null or empty')}"
onBlur="controller.chekValidProjectCode(self)" />
constraint="@{controller.chekValidProjectCode}" />
<checkbox label="${i18n:_('Generate code')}"
checked="@{controller.codeAutogenerated}" />
</hbox>