Validace entit přes hibernate validation framework
This commit is contained in:
@@ -13,6 +13,7 @@ public class AbstractOwnedService<T extends OwnedDataModel> extends AbstractServ
|
||||
@Override
|
||||
@Transactional
|
||||
public void add(T entity) {
|
||||
validate(entity);
|
||||
entity.setCreated(new Date());
|
||||
entity.setOwnedBy(getLoggedInUser());
|
||||
dao.add(entity);
|
||||
@@ -24,6 +25,7 @@ public class AbstractOwnedService<T extends OwnedDataModel> extends AbstractServ
|
||||
if (entity.getCreated() == null) {
|
||||
add(entity);
|
||||
} else {
|
||||
validate(entity);
|
||||
entity.setModifiedBy(getLoggedInUser());
|
||||
entity.setModified(new Date());
|
||||
dao.modify(entity);
|
||||
|
||||
@@ -28,6 +28,7 @@ public abstract class AbstractService<T extends DataModel> implements Service<T>
|
||||
@Override
|
||||
@Transactional
|
||||
public void add(T entity) {
|
||||
validate(entity);
|
||||
entity.setCreated(new Date());
|
||||
dao.add(entity);
|
||||
}
|
||||
@@ -38,6 +39,7 @@ public abstract class AbstractService<T extends DataModel> implements Service<T>
|
||||
if (entity.getCreated() == null) {
|
||||
add(entity);
|
||||
} else {
|
||||
validate(entity);
|
||||
entity.setModified(new Date());
|
||||
dao.modify(entity);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import info.bukova.isspst.services.ValidationException;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.dao.DataIntegrityViolationException;
|
||||
import org.zkoss.bind.annotation.BindingParam;
|
||||
import org.zkoss.bind.annotation.Command;
|
||||
import org.zkoss.bind.annotation.ExecutionArgParam;
|
||||
@@ -46,7 +45,7 @@ public class FormViewModel<T extends DataModel> {
|
||||
}
|
||||
|
||||
Messagebox.show("Chyba validace", "Chyba", Messagebox.OK, Messagebox.ERROR);
|
||||
} catch (DataIntegrityViolationException e) {
|
||||
} catch (Exception e) {
|
||||
dataBean.setCreated(null);
|
||||
e.printStackTrace();
|
||||
Messagebox.show("Chyba při ukládání záznamu", "Chyba", Messagebox.OK, Messagebox.ERROR);
|
||||
|
||||
Reference in New Issue
Block a user