diff --git a/src/main/java/info/bukova/isspst/data/Building.java b/src/main/java/info/bukova/isspst/data/Building.java index 8bc8beda..e3be3304 100644 --- a/src/main/java/info/bukova/isspst/data/Building.java +++ b/src/main/java/info/bukova/isspst/data/Building.java @@ -3,6 +3,10 @@ package info.bukova.isspst.data; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import javax.validation.constraints.NotNull; + +import org.hibernate.validator.constraints.NotBlank; +import org.hibernate.validator.constraints.NotEmpty; @Entity @Table(name="BUILDING") @@ -22,6 +26,9 @@ public class Building extends BaseData implements DataModel { /** * @return the code */ + @NotBlank(message = "${labels.BuildingsFormCodeConstr}") + @NotNull(message = "${labels.BuildingsFormCodeConstr}") + @NotEmpty(message = "${labels.BuildingsFormCodeConstr}") public String getCode() { return code; } diff --git a/src/main/java/info/bukova/isspst/services/BuildingService.java b/src/main/java/info/bukova/isspst/services/buildings/BuildingService.java similarity index 54% rename from src/main/java/info/bukova/isspst/services/BuildingService.java rename to src/main/java/info/bukova/isspst/services/buildings/BuildingService.java index 919c30d3..1c6cae7d 100644 --- a/src/main/java/info/bukova/isspst/services/BuildingService.java +++ b/src/main/java/info/bukova/isspst/services/buildings/BuildingService.java @@ -1,6 +1,7 @@ -package info.bukova.isspst.services; +package info.bukova.isspst.services.buildings; import info.bukova.isspst.data.Building; +import info.bukova.isspst.services.Service; public interface BuildingService extends Service { diff --git a/src/main/java/info/bukova/isspst/services/BuildingServiceImpl.java b/src/main/java/info/bukova/isspst/services/buildings/BuildingServiceImpl.java similarity index 58% rename from src/main/java/info/bukova/isspst/services/BuildingServiceImpl.java rename to src/main/java/info/bukova/isspst/services/buildings/BuildingServiceImpl.java index 57abc7fe..1683a8c2 100644 --- a/src/main/java/info/bukova/isspst/services/BuildingServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/buildings/BuildingServiceImpl.java @@ -1,6 +1,7 @@ -package info.bukova.isspst.services; +package info.bukova.isspst.services.buildings; import info.bukova.isspst.data.Building; +import info.bukova.isspst.services.AbstractService; public class BuildingServiceImpl extends AbstractService implements BuildingService{ diff --git a/src/main/java/info/bukova/isspst/ui/BuildingList.java b/src/main/java/info/bukova/isspst/ui/BuildingList.java index 94ffe808..6b9d50e9 100644 --- a/src/main/java/info/bukova/isspst/ui/BuildingList.java +++ b/src/main/java/info/bukova/isspst/ui/BuildingList.java @@ -1,7 +1,7 @@ package info.bukova.isspst.ui; import info.bukova.isspst.data.Building; -import info.bukova.isspst.services.BuildingService; +import info.bukova.isspst.services.buildings.BuildingService; import org.zkoss.bind.annotation.Init; import org.zkoss.zk.ui.select.annotation.WireVariable; diff --git a/src/main/java/info/bukova/isspst/ui/ListViewModel.java b/src/main/java/info/bukova/isspst/ui/ListViewModel.java index 12e948d2..1464678d 100644 --- a/src/main/java/info/bukova/isspst/ui/ListViewModel.java +++ b/src/main/java/info/bukova/isspst/ui/ListViewModel.java @@ -22,7 +22,7 @@ import org.zkoss.zul.Messagebox; import org.zkoss.zul.Window; public class ListViewModel { - + private boolean confirmDelete = false; private boolean filter = false; private Window editWin; @@ -37,29 +37,29 @@ public class ListViewModel { private boolean sortDesc = true; private boolean newRec = false; private boolean fullFill = false; - + protected Service service; protected Class dataClass; protected String formZul; protected Filter dataFilter; - + public List getDataList() { if (dataList == null) { dataList = new ArrayList(); loadFromDbSync(); } - + return dataList; } - + public void setDataBean(T data) { this.dataBean = data; } - + public void setDataFilter(Filter dataFilter) { this.dataFilter = dataFilter; } - + public T getFilterTemplate() { if (filterTemplate == null) { try { @@ -70,18 +70,18 @@ public class ListViewModel { e.printStackTrace(); } } - + return filterTemplate; } - + public T getDataBean() { return dataBean; } - + public boolean getConfirmDelete() { return confirmDelete; } - + public boolean getFilter() { return this.filter; } @@ -89,21 +89,20 @@ public class ListViewModel { public boolean getFullFill() { return fullFill; } - + protected void newRecMode() { newRec = true; } - + protected void setEditBean(T edit) { this.editBean = edit; } - - + @Command - @NotifyChange({"filter", "dataList", "dataBean"}) + @NotifyChange({ "filter", "dataList", "dataBean" }) public void filter() { filter = !filter; - + if (!filter) { dataList = fullList; dataBean = null; @@ -113,19 +112,19 @@ public class ListViewModel { dataBean = null; } } - + @Command @NotifyChange("dataList") public void doFilter() { if (dataFilter == null) { return; } - + List result = service.filterList(fullList, dataFilter); selIndex = -1; dataList = result; } - + @Command public void addNew() { try { @@ -138,66 +137,72 @@ public class ListViewModel { e.printStackTrace(); } } - + @Command public void edit() { int index = dataList.indexOf(dataBean); newRec = false; - if (index != -1) { + if (index != -1) { selIndex = index; } editBean = service.getById(dataBean.getId()); showForm(); } - + @Command @NotifyChange("confirmDelete") public void delObject() { confirmDelete = true; } - + @Command - @NotifyChange({"dataList", "dataBean"}) + @NotifyChange({ "dataList", "dataBean" }) public void delete() { - Messagebox.show("Opravdu smazat?", "Smazat záznam", Messagebox.YES|Messagebox.NO, - Messagebox.QUESTION, new EventListener() { - + Messagebox.show("Opravdu smazat?", "Smazat záznam", Messagebox.YES + | Messagebox.NO, Messagebox.QUESTION, + new EventListener() { + @Override public void onEvent(Event evt) throws Exception { - if (((Integer)evt.getData()).intValue() == Messagebox.YES) { + if (((Integer) evt.getData()).intValue() == Messagebox.YES) { try { service.delete(dataBean); dataList.remove(dataBean); dataBean = null; - BindUtils.postNotifyChange(null, null, ListViewModel.this, "dataList"); - BindUtils.postNotifyChange(null, null, ListViewModel.this, "dataBean"); + BindUtils.postNotifyChange(null, null, + ListViewModel.this, "dataList"); + BindUtils.postNotifyChange(null, null, + ListViewModel.this, "dataBean"); } catch (DataIntegrityViolationException e) { - Messagebox.show("Chyba při mazání záznamu", "Chyba", Messagebox.OK, Messagebox.ERROR); + Messagebox.show("Chyba při mazání záznamu", + "Chyba", Messagebox.OK, + Messagebox.ERROR); } } } - }); - + }); + confirmDelete = false; } - - @NotifyChange({"dataList", "dataBean"}) + + @NotifyChange({ "dataList", "dataBean" }) private void onDelete() { try { service.delete(dataBean); dataList.remove(dataBean); dataBean = null; } catch (DataIntegrityViolationException e) { - Messagebox.show("Chyba při mazání záznamu", "Chyba", Messagebox.OK, Messagebox.ERROR); + Messagebox.show("Chyba při mazání záznamu", "Chyba", Messagebox.OK, + Messagebox.ERROR); } } - + @GlobalCommand - @NotifyChange({"dataList", "dataBean"}) + @NotifyChange({ "dataList", "dataBean" }) public void refresh() { - /*if (editBean != null && !editBean.isValid()) { + if (editBean != null && !editBean.isValid()) { return; - }*/ + } if (editBean.getCreated() == null) { return; } @@ -214,9 +219,9 @@ public class ListViewModel { dataList.set(selIndex, editBean); } } - + @GlobalCommand - @NotifyChange({"dataList", "dataBean", "fullFill"}) + @NotifyChange({ "dataList", "dataBean", "fullFill" }) public void reload() { dataBean = null; dataList.clear(); @@ -229,66 +234,66 @@ public class ListViewModel { if (editBean != null && !editBean.isValid()) { return; } - - if (selIndex > dataList.size() -1) { + + if (selIndex > dataList.size() - 1) { selIndex = -1; } if (newRec) { - selIndex = dataList.size() -1; + selIndex = dataList.size() - 1; newRec = false; } } - + @Command @NotifyChange("dataBean") public void onSort(@BindingParam("column") String column) { if (sortCol == null || this.sortCol.equals(column)) this.sortDesc = !this.sortDesc; - + this.sortCol = column; selIndex = -1; dataBean = null; } - + public int getSelIndex() { return this.selIndex; } - + @Command - @NotifyChange({"dataList", "fullFill"}) + @NotifyChange({ "dataList", "fullFill" }) public void fullFill() { if (fullFill && dataList.isEmpty()) { dataList.addAll(tmpList); fullList = dataList; } } - -// private void loadFromDb() { -// Thread fillThread = new Thread(new Runnable() { -// -// @Override -// public void run() { -// tmpList = service.getAll(); -// -// try { -// Thread.sleep(200); -// } catch (InterruptedException e) { -// e.printStackTrace(); -// } -// -// fullFill = true; -// } -// }); -// -// fillThread.start(); -// } - + + // private void loadFromDb() { + // Thread fillThread = new Thread(new Runnable() { + // + // @Override + // public void run() { + // tmpList = service.getAll(); + // + // try { + // Thread.sleep(200); + // } catch (InterruptedException e) { + // e.printStackTrace(); + // } + // + // fullFill = true; + // } + // }); + // + // fillThread.start(); + // } + private void loadFromDbSync() { dataList.addAll(service.getAll()); fullList = dataList; } - + protected void showForm() { Map arg = new HashMap(); arg.put("selected", editBean); diff --git a/src/main/webapp/WEB-INF/jdbc.properties b/src/main/webapp/WEB-INF/jdbc.properties index 3483bc97..306c5336 100644 --- a/src/main/webapp/WEB-INF/jdbc.properties +++ b/src/main/webapp/WEB-INF/jdbc.properties @@ -1,5 +1,5 @@ jdbc.driverClassName=com.mysql.jdbc.Driver jdbc.dialect=org.hibernate.dialect.MySQLDialect -jdbc.databaseurl=jdbc:mysql://127.0.0.1:3306/isspst +jdbc.databaseurl=jdbc:mysql://127.0.0.1:3306/isspst?characterEncoding=UTF-8 jdbc.username=root jdbc.password=xsacfgd \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/spring/root-context.xml b/src/main/webapp/WEB-INF/spring/root-context.xml index 931b4e11..751fa526 100644 --- a/src/main/webapp/WEB-INF/spring/root-context.xml +++ b/src/main/webapp/WEB-INF/spring/root-context.xml @@ -1,131 +1,117 @@ - - + - + - - - + + + - - - - - - classpath:hibernate.cfg.xml - - - - ${jdbc.dialect} - true - update - - - - - - - - - - - - + + + + + + classpath:hibernate.cfg.xml + + + + ${jdbc.dialect} + true + update + + + + + + + + + + + + - - - - - + + + + + - + - + - + - - - + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - + + + + - - + + - + - + - - - + + + + - + - - + + - + - - + + - + - + - + @@ -133,9 +119,9 @@ - + - + - + diff --git a/src/main/webapp/app/formButtons.zul b/src/main/webapp/app/formButtons.zul index 0c48ea0f..d947ff44 100644 --- a/src/main/webapp/app/formButtons.zul +++ b/src/main/webapp/app/formButtons.zul @@ -1,4 +1,9 @@ -