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); } }
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"; }