public String deleteTask(long id) { FacesMessage msg = new FacesMessage(); try { taskEJB.delete(id); JsfUtil.addSuccessMessage("Task has been deleted"); } catch (Exception ex) { JsfUtil.addErrorMessage(ex, "Failed to delete message"); } return prepareTask(); }
public String updateTask() { try { // fetch task and update before sending to database Task t = taskEJB.getTask(taskBean.getTaskId()); t.setAssignedTo(accountEJB.getUser(taskBean.getAssignedUser())); t.setOwner(accountEJB.getUser(taskBean.getOwner())); t.setCompleted(taskBean.isCompleted()); t.setDueDate(taskBean.getDueDate()); t.setNote(taskBean.getNote()); t.setTitle(taskBean.getTitle()); t.setPriority(taskBean.getPriority()); taskEJB.update(t); FacesMessage message = new FacesMessage(); message.setSummary("Task is updated"); message.setSeverity(FacesMessage.SEVERITY_INFO); FacesContext ctxt = FacesContext.getCurrentInstance(); ctxt.addMessage(null, message); } catch (Exception ex) { Logger.getLogger(TaskController.class.getSimpleName()).log(Level.SEVERE, ex.getMessage()); } return "tasks"; }
public String prepareTask(ActionEvent event) { User owner = null; User assignedTo = null; if (searchData.getTaskBy() > -1) { if (searchData.getTaskBy() > 0) { owner = login.getUser(); } } taskCollection = taskEJB.getTasks( owner, assignedTo, searchData.getStatus(), searchData.getStartDate(), searchData.getEndDate(), 0, 20); return "tasks"; }
public String createTask() { try { Task task = new Task(); task.setTitle(taskBean.getTitle()); task.setNote(taskBean.getNote()); task.setCompleted(taskBean.isCompleted()); task.setDueDate(taskBean.getDueDate()); task.setCreateDate(new Date()); task.setOwner(login.getUser()); task.setAssignedTo(accountEJB.getUser(taskBean.getAssignedUser())); task.setPriority(taskBean.getPriority()); taskEJB.createTask(task); JsfUtil.addSuccessMessage("Task created"); return prepareCreate(); } catch (Exception ex) { JsfUtil.addErrorMessage(ex.getMessage()); return null; } }
public void viewTask(long id) { try { // get task Task task = taskEJB.getTask(id); // assign task to backing beam taskBean = new TaskBean(); taskBean.setTitle(task.getTitle()); taskBean.setNote(task.getNote()); taskBean.setAssignedUser(task.getAssignedTo().getId()); taskBean.setCompleted(task.isCompleted()); taskBean.setDueDate(task.getDueDate()); taskBean.setPriority(task.getPriority()); taskBean.setOwner(task.getOwner().getId()); taskBean.setCreatedDate(task.getCreateDate()); taskBean.setTaskId(task.getId()); FacesContext ctxt = FacesContext.getCurrentInstance(); ExternalContext exCtx = ctxt.getExternalContext(); exCtx.addResponseHeader("taskId", String.valueOf(id)); exCtx.redirect("edittask.xhtml?action=view"); } catch (IOException ex) { Logger.getLogger(TaskController.class.getName()).log(Level.SEVERE, null, ex); } }