V případě zadání duplicitní hodnoty se zpracují potřebné výjimky a
zobrazí se v messageboxu hlášení o důvodu chyby. closes #127
This commit is contained in:
@@ -5,9 +5,11 @@ import info.bukova.isspst.data.DataModel;
|
||||
import info.bukova.isspst.services.Service;
|
||||
import info.bukova.isspst.services.ValidationException;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.exception.ConstraintViolationException;
|
||||
import org.springframework.dao.DataIntegrityViolationException;
|
||||
import org.springframework.security.access.AccessDeniedException;
|
||||
import org.zkoss.bind.annotation.BindingParam;
|
||||
import org.zkoss.bind.annotation.Command;
|
||||
@@ -17,36 +19,43 @@ import org.zkoss.bind.annotation.NotifyChange;
|
||||
import org.zkoss.zul.Messagebox;
|
||||
import org.zkoss.zul.Window;
|
||||
|
||||
public class FormViewModel<T extends DataModel> {
|
||||
|
||||
public class FormViewModel<T extends DataModel>
|
||||
{
|
||||
|
||||
private T dataBean;
|
||||
private Map<String, String> errMessages;
|
||||
private Service<T> service;
|
||||
private boolean newRec;
|
||||
private ServiceConstraint<T> constraint;
|
||||
|
||||
|
||||
@Init
|
||||
public void init(@ExecutionArgParam("selected") T selected, @ExecutionArgParam("service") Service<T> service) {
|
||||
public void init(@ExecutionArgParam("selected") T selected, @ExecutionArgParam("service") Service<T> service)
|
||||
{
|
||||
this.dataBean = selected;
|
||||
this.service = service;
|
||||
constraint = new ServiceConstraint<T>();
|
||||
constraint.setDataBean(selected);
|
||||
constraint.setService(service);
|
||||
if (selected.getId() == 0 && selected.getCreated() == null) {
|
||||
if (selected.getId() == 0 && selected.getCreated() == null)
|
||||
{
|
||||
newRec = true;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
newRec = false;
|
||||
}
|
||||
}
|
||||
|
||||
public ServiceConstraint<T> getConstriant() {
|
||||
|
||||
public ServiceConstraint<T> getConstriant()
|
||||
{
|
||||
return constraint;
|
||||
}
|
||||
|
||||
public T getDataBean() {
|
||||
|
||||
public T getDataBean()
|
||||
{
|
||||
return dataBean;
|
||||
}
|
||||
|
||||
|
||||
public boolean isNewRec()
|
||||
{
|
||||
return this.newRec;
|
||||
@@ -59,52 +68,103 @@ public class FormViewModel<T extends DataModel> {
|
||||
|
||||
@Command
|
||||
@NotifyChange("errMessages")
|
||||
public void save(@BindingParam("window") Window win) {
|
||||
try {
|
||||
if (newRec) {
|
||||
public void save(@BindingParam("window") Window win)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (newRec)
|
||||
{
|
||||
doAdd();
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
doSave();
|
||||
}
|
||||
win.detach();
|
||||
} catch (ValidationException e) {
|
||||
}
|
||||
catch (ValidationException e)
|
||||
{
|
||||
errMessages = e.getMessages();
|
||||
String classErr = errMessages.get("CLASS_ERR");
|
||||
|
||||
if (classErr == null) {
|
||||
|
||||
if (classErr == null)
|
||||
{
|
||||
classErr = "";
|
||||
}
|
||||
|
||||
|
||||
Messagebox.show(StringUtils.localize("DbValidationError"), StringUtils.localize("Error"), Messagebox.OK, Messagebox.ERROR);
|
||||
} catch (AccessDeniedException e) {
|
||||
}
|
||||
catch (AccessDeniedException e)
|
||||
{
|
||||
Messagebox.show(StringUtils.localize("ErrorRights"), StringUtils.localize("Error"), Messagebox.OK, Messagebox.ERROR);
|
||||
} catch (ConstraintViolationException e) {
|
||||
}
|
||||
catch (ConstraintViolationException e)
|
||||
{
|
||||
Messagebox.show(StringUtils.localizeDbErr(e.getSQLException().getMessage()), StringUtils.localize("Error"), Messagebox.OK, Messagebox.ERROR);
|
||||
dataBean.setValid(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
catch (DataIntegrityViolationException e)
|
||||
{
|
||||
Throwable actualException = e;
|
||||
Throwable previousException = actualException.getCause();
|
||||
String msg = actualException.getLocalizedMessage();
|
||||
boolean printStackTree = true;
|
||||
|
||||
if (previousException != null)
|
||||
{
|
||||
if (previousException instanceof ConstraintViolationException)
|
||||
{
|
||||
ConstraintViolationException cve = (ConstraintViolationException) previousException;
|
||||
SQLException sqle = cve.getSQLException();
|
||||
int errCode = sqle.getErrorCode();
|
||||
|
||||
if (errCode == 1062)
|
||||
{
|
||||
printStackTree = false;
|
||||
msg = sqle.getMessage();
|
||||
msg = StringUtils.localizeDbErr(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (printStackTree)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Messagebox.show(StringUtils.localize("DbSaveError") + "\n\n" + msg, StringUtils.localize("Error"), Messagebox.OK, Messagebox.ERROR);
|
||||
dataBean.setValid(false);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
Messagebox.show(StringUtils.localize("DbSaveError"), StringUtils.localize("Error"), Messagebox.OK, Messagebox.ERROR);
|
||||
dataBean.setValid(false);
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, String> getErrMessages() {
|
||||
public Map<String, String> getErrMessages()
|
||||
{
|
||||
return errMessages;
|
||||
}
|
||||
|
||||
protected void setErrMesages(Map<String, String> msgs) {
|
||||
|
||||
protected void setErrMesages(Map<String, String> msgs)
|
||||
{
|
||||
this.errMessages = msgs;
|
||||
}
|
||||
|
||||
protected void doSave() {
|
||||
|
||||
protected void doSave()
|
||||
{
|
||||
service.update(dataBean);
|
||||
}
|
||||
|
||||
protected void doAdd() {
|
||||
|
||||
protected void doAdd()
|
||||
{
|
||||
service.add(dataBean);
|
||||
}
|
||||
|
||||
public boolean isCanSave() {
|
||||
|
||||
public boolean isCanSave()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -117,11 +117,11 @@ UsersGridColumnPersonalID=Osobní číslo
|
||||
UsersGridColumnFirstName=Jméno
|
||||
UsersGridColumnSureName=Příjmení
|
||||
|
||||
AgendaMaterial=Materiál
|
||||
MaterialFormTitle=Materiál
|
||||
AgendaMaterial=Skupiny materiálu
|
||||
MaterialFormTitle=Skupina materiálu
|
||||
|
||||
AgendaServices=Služby
|
||||
ServiceFormTitle=Služba
|
||||
AgendaServices=Skupiny služeb
|
||||
ServiceFormTitle=Skupina služeb
|
||||
|
||||
AgendaWorkgroups=Střediska / komise
|
||||
WorkgroupFormTitle=Pracvní skupina
|
||||
@@ -239,7 +239,7 @@ ErrorRights=K vykobání této operace nemáte dostatečná oprávnění
|
||||
|
||||
DbDeleteRecord=Smazat záznam
|
||||
DbReallyDelete=Opravdu chcete smazat tento záznam?
|
||||
DbDuplicateEntry=Chyba při ukládání záznamu: Duplicitní záznam
|
||||
DbDuplicateEntry=Duplicitní hodnota
|
||||
DbForKey= pro klíč
|
||||
DbCannotDelete=Chyba při mazání záznamu: Záznam nelze smazat protože na něj odkazuje jiný záznam
|
||||
DbSaveError=Chyba při ukládání záznamu
|
||||
|
||||
Reference in New Issue
Block a user