Exemplo n.º 1
0
 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);
   }
 }
Exemplo n.º 2
0
  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";
  }
Exemplo n.º 3
0
  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;
    }
  }