use of com.vaadin.data.Validator.InvalidValueException in project Activiti by Activiti.
the class FormPropertiesForm method initListeners.
protected void initListeners() {
submitFormButton.addListener(new ClickListener() {
private static final long serialVersionUID = -6091586145870618870L;
public void buttonClick(ClickEvent event) {
// Extract the submitted values from the form. Throws exception when validation fails.
try {
Map<String, String> formProperties = formPropertiesComponent.getFormPropertyValues();
fireEvent(new FormPropertiesEvent(FormPropertiesForm.this, FormPropertiesEvent.TYPE_SUBMIT, formProperties));
submitFormButton.setComponentError(null);
} catch (InvalidValueException ive) {
// Error is presented to user by the form component
}
}
});
cancelFormButton.addListener(new ClickListener() {
private static final long serialVersionUID = -8980500491522472381L;
public void buttonClick(ClickEvent event) {
fireEvent(new FormPropertiesEvent(FormPropertiesForm.this, FormPropertiesEvent.TYPE_CANCEL));
submitFormButton.setComponentError(null);
}
});
}
use of com.vaadin.data.Validator.InvalidValueException in project VaadinUtils by rlsutton1.
the class ReportParameter method validateField.
protected boolean validateField(AbstractField<T> field) {
boolean valid = false;
try {
field.setComponentError(null);
if (validateListener != null) {
validateListener.setComponentError(null);
}
field.validate();
valid = true;
} catch (final InvalidValueException e) {
ErrorMessage componentError = new ErrorMessage() {
private static final long serialVersionUID = -2976235476811651668L;
@Override
public String getFormattedHtmlMessage() {
return e.getHtmlMessage();
}
@Override
public ErrorLevel getErrorLevel() {
return ErrorLevel.ERROR;
}
};
field.setComponentError(componentError);
if (validateListener != null) {
validateListener.setComponentError(componentError);
}
}
return valid;
}
use of com.vaadin.data.Validator.InvalidValueException in project VaadinUtils by rlsutton1.
the class BaseCrudView method handleInvalidValueException.
protected void handleInvalidValueException(InvalidValueException m) {
String causeMessage = "";
for (InvalidValueException cause : m.getCauses()) {
causeMessage += cause.getMessage() + ". ";
}
if (m.getMessage() != null && m.getMessage().length() > 0) {
causeMessage += m.getMessage() + ". ";
}
Notification.show("Please fix the form errors and then try again.\n\n " + causeMessage, Type.ERROR_MESSAGE);
}
use of com.vaadin.data.Validator.InvalidValueException in project VaadinUtils by rlsutton1.
the class BaseCrudView method save.
@Override
public void save() {
boolean selected = false;
try {
commitFieldGroup();
validateChildren();
CrudEventType eventType = CrudEventType.EDIT;
if (newEntity != null) {
if (!okToSave(newEntity)) {
return;
}
eventType = CrudEventType.CREATE;
interceptSaveValues(newEntity);
Object id = container.addEntity(newEntity.getEntity());
EntityItem<E> item = container.getItem(id);
fieldGroup.setItemDataSource(item);
selected = true;
if (restoreDelete) {
activateEditMode(false);
restoreDelete = false;
}
searchField.setReadOnly(false);
clearButton.setEnabled(true);
} else {
EntityItem<E> current = entityTable.getCurrent();
if (current != null) {
if (!okToSave(current)) {
return;
}
interceptSaveValues(current);
}
}
// commit the row to the database, and retrieve the possibly new
// entity
E newEntity = commitContainerAndGetEntityFromDB();
if (newEntity == null) {
throw new RuntimeException("An error occurred, unable to retrieve updated record. Failed to save changes");
}
newEntity = EntityManagerProvider.getEntityManager().merge(newEntity);
for (ChildCrudListener<E> commitListener : childCrudListeners) {
// of children
if (commitListener.isDirty()) {
commitListener.committed(newEntity);
}
}
EntityManagerProvider.getEntityManager().flush();
// children may have been added to the parent, evict the parent from
// the JPA cache so it will get updated
EntityManagerProvider.getEntityManager().getEntityManagerFactory().getCache().evict(entityClass, newEntity.getId());
newEntity = EntityManagerProvider.merge(newEntity);
postSaveAction(newEntity);
EntityManagerProvider.getEntityManager().flush();
reloadDataFromDB(newEntity.getId());
CrudEventDistributer.publishEvent(this, eventType, newEntity);
if (eventType == CrudEventType.CREATE) {
addFilterToShowNewRow(newEntity);
container.discard();
}
this.newEntity = null;
searchField.setReadOnly(false);
clearButton.setEnabled(true);
// select has been moved to here because when it happens earlier,
// child cruds are caused to discard their data before saving it for
// a new record
entityTable.select(newEntity.getId());
splitPanel.showFirstComponent();
Notification.show("Changes Saved", "Any changes you have made have been saved.", Type.HUMANIZED_MESSAGE);
// return save/edit buttons to default settings
buttonLayout.setDefaultState();
} catch (Exception e) {
if (e instanceof InvalidValueException) {
handleInvalidValueException((InvalidValueException) e);
} else if (e.getCause() instanceof InvalidValueException) {
handleInvalidValueException((InvalidValueException) e.getCause());
} else {
ErrorWindow.showErrorWindow(e);
}
} finally {
if (newEntity != null) {
if (selected && entityTable.getCurrent() != null) {
container.removeItem(entityTable.getCurrent());
}
}
buttonLayout.setDefaultState();
}
}
use of com.vaadin.data.Validator.InvalidValueException in project VaadinUtils by rlsutton1.
the class JasperReportScheduleLayout method interceptSaveValues.
@Override
protected void interceptSaveValues(EntityItem<ReportEmailScheduleEntity> entityItem) {
ReportEmailScheduleEntity entity = entityItem.getEntity();
entity.setNextScheduledRunTime(entity.getScheduleMode().getNextRuntime(entity, new Date()));
List<ReportEmailRecipient> recips = entity.getRecipients();
Set<ReportEmailRecipient> matchedRecips = new HashSet<ReportEmailRecipient>();
for (EmailTargetLine line : emailTargetLayout.getTargets()) {
// check if the recipient exists
String email = (String) line.targetAddress.getValue();
if (email != null && email.length() > 0) {
// String email = (String)
// item.getItemProperty("id").getValue();
boolean found = false;
for (ReportEmailRecipient recip : recips) {
if (recip.getEmail() != null && recip.getEmail().equalsIgnoreCase(email)) {
found = true;
recip.setVisibility((ReportEmailRecipientVisibility) line.targetTypeCombo.getValue());
matchedRecips.add(recip);
break;
}
}
// if not then add them
if (!found) {
ReportEmailRecipient reportEmailRecipient = new ReportEmailRecipient();
reportEmailRecipient.setEmail(email);
reportEmailRecipient.setVisibility((ReportEmailRecipientVisibility) line.targetTypeCombo.getValue());
recips.add(reportEmailRecipient);
matchedRecips.add(reportEmailRecipient);
}
}
}
recips.clear();
recips.addAll(matchedRecips);
if (recips.size() == 0) {
throw new InvalidValueException("Select at least one Recipient");
}
saveChangesToReportParameters(entity);
}
Aggregations