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.Service;
|
||||||
import info.bukova.isspst.services.ValidationException;
|
import info.bukova.isspst.services.ValidationException;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.hibernate.exception.ConstraintViolationException;
|
import org.hibernate.exception.ConstraintViolationException;
|
||||||
|
import org.springframework.dao.DataIntegrityViolationException;
|
||||||
import org.springframework.security.access.AccessDeniedException;
|
import org.springframework.security.access.AccessDeniedException;
|
||||||
import org.zkoss.bind.annotation.BindingParam;
|
import org.zkoss.bind.annotation.BindingParam;
|
||||||
import org.zkoss.bind.annotation.Command;
|
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.Messagebox;
|
||||||
import org.zkoss.zul.Window;
|
import org.zkoss.zul.Window;
|
||||||
|
|
||||||
public class FormViewModel<T extends DataModel> {
|
public class FormViewModel<T extends DataModel>
|
||||||
|
{
|
||||||
|
|
||||||
private T dataBean;
|
private T dataBean;
|
||||||
private Map<String, String> errMessages;
|
private Map<String, String> errMessages;
|
||||||
private Service<T> service;
|
private Service<T> service;
|
||||||
private boolean newRec;
|
private boolean newRec;
|
||||||
private ServiceConstraint<T> constraint;
|
private ServiceConstraint<T> constraint;
|
||||||
|
|
||||||
@Init
|
@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.dataBean = selected;
|
||||||
this.service = service;
|
this.service = service;
|
||||||
constraint = new ServiceConstraint<T>();
|
constraint = new ServiceConstraint<T>();
|
||||||
constraint.setDataBean(selected);
|
constraint.setDataBean(selected);
|
||||||
constraint.setService(service);
|
constraint.setService(service);
|
||||||
if (selected.getId() == 0 && selected.getCreated() == null) {
|
if (selected.getId() == 0 && selected.getCreated() == null)
|
||||||
|
{
|
||||||
newRec = true;
|
newRec = true;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
newRec = false;
|
newRec = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ServiceConstraint<T> getConstriant() {
|
public ServiceConstraint<T> getConstriant()
|
||||||
|
{
|
||||||
return constraint;
|
return constraint;
|
||||||
}
|
}
|
||||||
|
|
||||||
public T getDataBean() {
|
public T getDataBean()
|
||||||
|
{
|
||||||
return dataBean;
|
return dataBean;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isNewRec()
|
public boolean isNewRec()
|
||||||
{
|
{
|
||||||
return this.newRec;
|
return this.newRec;
|
||||||
@@ -59,52 +68,103 @@ public class FormViewModel<T extends DataModel> {
|
|||||||
|
|
||||||
@Command
|
@Command
|
||||||
@NotifyChange("errMessages")
|
@NotifyChange("errMessages")
|
||||||
public void save(@BindingParam("window") Window win) {
|
public void save(@BindingParam("window") Window win)
|
||||||
try {
|
{
|
||||||
if (newRec) {
|
try
|
||||||
|
{
|
||||||
|
if (newRec)
|
||||||
|
{
|
||||||
doAdd();
|
doAdd();
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
doSave();
|
doSave();
|
||||||
}
|
}
|
||||||
win.detach();
|
win.detach();
|
||||||
} catch (ValidationException e) {
|
}
|
||||||
|
catch (ValidationException e)
|
||||||
|
{
|
||||||
errMessages = e.getMessages();
|
errMessages = e.getMessages();
|
||||||
String classErr = errMessages.get("CLASS_ERR");
|
String classErr = errMessages.get("CLASS_ERR");
|
||||||
|
|
||||||
if (classErr == null) {
|
if (classErr == null)
|
||||||
|
{
|
||||||
classErr = "";
|
classErr = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
Messagebox.show(StringUtils.localize("DbValidationError"), StringUtils.localize("Error"), Messagebox.OK, Messagebox.ERROR);
|
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);
|
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);
|
Messagebox.show(StringUtils.localizeDbErr(e.getSQLException().getMessage()), StringUtils.localize("Error"), Messagebox.OK, Messagebox.ERROR);
|
||||||
dataBean.setValid(false);
|
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();
|
e.printStackTrace();
|
||||||
Messagebox.show(StringUtils.localize("DbSaveError"), StringUtils.localize("Error"), Messagebox.OK, Messagebox.ERROR);
|
Messagebox.show(StringUtils.localize("DbSaveError"), StringUtils.localize("Error"), Messagebox.OK, Messagebox.ERROR);
|
||||||
dataBean.setValid(false);
|
dataBean.setValid(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, String> getErrMessages() {
|
public Map<String, String> getErrMessages()
|
||||||
|
{
|
||||||
return errMessages;
|
return errMessages;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setErrMesages(Map<String, String> msgs) {
|
protected void setErrMesages(Map<String, String> msgs)
|
||||||
|
{
|
||||||
this.errMessages = msgs;
|
this.errMessages = msgs;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void doSave() {
|
protected void doSave()
|
||||||
|
{
|
||||||
service.update(dataBean);
|
service.update(dataBean);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void doAdd() {
|
protected void doAdd()
|
||||||
|
{
|
||||||
service.add(dataBean);
|
service.add(dataBean);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isCanSave() {
|
public boolean isCanSave()
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -117,11 +117,11 @@ UsersGridColumnPersonalID=Osobní číslo
|
|||||||
UsersGridColumnFirstName=Jméno
|
UsersGridColumnFirstName=Jméno
|
||||||
UsersGridColumnSureName=Příjmení
|
UsersGridColumnSureName=Příjmení
|
||||||
|
|
||||||
AgendaMaterial=Materiál
|
AgendaMaterial=Skupiny materiálu
|
||||||
MaterialFormTitle=Materiál
|
MaterialFormTitle=Skupina materiálu
|
||||||
|
|
||||||
AgendaServices=Služby
|
AgendaServices=Skupiny služeb
|
||||||
ServiceFormTitle=Služba
|
ServiceFormTitle=Skupina služeb
|
||||||
|
|
||||||
AgendaWorkgroups=Střediska / komise
|
AgendaWorkgroups=Střediska / komise
|
||||||
WorkgroupFormTitle=Pracvní skupina
|
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
|
DbDeleteRecord=Smazat záznam
|
||||||
DbReallyDelete=Opravdu chcete smazat tento 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íč
|
DbForKey= pro klíč
|
||||||
DbCannotDelete=Chyba při mazání záznamu: Záznam nelze smazat protože na něj odkazuje jiný záznam
|
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
|
DbSaveError=Chyba při ukládání záznamu
|
||||||
|
|||||||
Reference in New Issue
Block a user