public void addDirectly() { JsfUtil.addSuccessMessage("1"); try { current.setCreatedAt(Calendar.getInstance().getTime()); current.setCreater(sessionController.loggedUser); getFacade().create(current); JsfUtil.addSuccessMessage(new MessageProvider().getValue("savedNewSuccessfully")); current = new MohArea(); } catch (Exception e) { JsfUtil.addErrorMessage(e, "Error"); } }
public MohArea searchItem(String itemName, boolean createNewIfNotPresent) { MohArea searchedItem = null; items = new ListDataModel(getFacade().findAll("name", itemName, true)); if (items.getRowCount() > 0) { items.setRowIndex(0); searchedItem = (MohArea) items.getRowData(); } else if (createNewIfNotPresent) { searchedItem = new MohArea(); searchedItem.setName(itemName); searchedItem.setCreatedAt(Calendar.getInstance().getTime()); searchedItem.setCreater(sessionController.loggedUser); getFacade().create(searchedItem); } return searchedItem; }
public String getAsString(FacesContext facesContext, UIComponent component, Object object) { if (object == null) { return null; } if (object instanceof MohArea) { MohArea o = (MohArea) object; return getStringKey(o.getId()); } else { throw new IllegalArgumentException( "object " + object + " is of type " + object.getClass().getName() + "; expected type: " + MohController.class.getName()); } }
public void prepareEdit() { if (current != null) { selectedItemIndex = intValue(current.getId()); this.prepareSelectControlDisable(); } else { JsfUtil.addErrorMessage(new MessageProvider().getValue("nothingToEdit")); } }
public void saveSelected() { if (sessionController.getPrivilege().isDemographyEdit() == false) { JsfUtil.addErrorMessage("You are not autherized to make changes to any content"); return; } if (selectedItemIndex > 0) { getFacade().edit(current); JsfUtil.addSuccessMessage(new MessageProvider().getValue("savedOldSuccessfully")); } else { current.setCreatedAt(Calendar.getInstance().getTime()); current.setCreater(sessionController.loggedUser); getFacade().create(current); JsfUtil.addSuccessMessage(new MessageProvider().getValue("savedNewSuccessfully")); } this.prepareSelect(); recreateModel(); getItems(); selectText = ""; selectedItemIndex = intValue(current.getId()); }
public void delete() { if (sessionController.getPrivilege().isDemographyDelete() == false) { JsfUtil.addErrorMessage("You are not autherized to delete any content"); return; } if (current != null) { current.setRetired(true); current.setRetiredAt(Calendar.getInstance().getTime()); current.setRetirer(sessionController.loggedUser); getFacade().edit(current); JsfUtil.addSuccessMessage(new MessageProvider().getValue("deleteSuccessful")); } else { JsfUtil.addErrorMessage(new MessageProvider().getValue("nothingToDelete")); } recreateModel(); getItems(); selectText = ""; selectedItemIndex = -1; current = null; this.prepareSelect(); }
public DataModel searchItems() { recreateModel(); if (items == null) { if (selectText.equals("")) { items = new ListDataModel(getFacade().findAll("name", true)); } else { items = new ListDataModel(getFacade().findAll("name", "%" + selectText + "%", true)); if (items.getRowCount() > 0) { items.setRowIndex(0); current = (MohArea) items.getRowData(); Long temLong = current.getId(); selectedItemIndex = intValue(temLong); } else { current = null; selectedItemIndex = -1; } } } return items; }