Example #1
0
  public String commentsave() {

    System.out.println("--------------commentsave-----------");
    User u = new User();
    u = (User) this.request.getSession().getAttribute("user_");
    System.out.println("User------" + u.toString());

    String content = this.binfo.getCommentcontent();
    String topicid = this.binfo.getId();
    this.comment = new Comment();
    this.comment.setContent(content);
    this.comment.setTopicid(Integer.parseInt(topicid));
    this.comment.setAuther(u.getId());
    this.comment.setUser(u);
    this.comment.setDate(CONSTANT.getNowTime());
    System.out.println("this.comment----" + this.comment.toString());
    try {
      bm.add(this.comment);
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    } catch (SQLException e) {
      e.printStackTrace();
    }

    this.constituteTopic(this.comment.getTopicid());
    this.updateTopicTime(this.comment.getTopicid(), this.comment.getDate());
    return "save";
  }
Example #2
0
  private void constituteTopic(int _topicid) {
    try {
      this.topic = bm.loadTopicWithCommentsByTopicId(_topicid);
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    } catch (SQLException e) {
      e.printStackTrace();
    }

    User u = new User();
    try {
      u = um.loadUserByid(this.topic.getAuther());
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    } catch (SQLException e) {
      e.printStackTrace();
    }
    this.topic.setUser(u);

    for (Comment comm : this.topic.getComments()) {
      User cu = new User();
      try {
        cu = um.loadUserByid(comm.getAuther());
      } catch (ClassNotFoundException e) {
        e.printStackTrace();
      } catch (SQLException e) {
        e.printStackTrace();
      }
      comm.setUser(cu);
      System.out.println("cu---" + cu.toString());
      System.out.println("Comm---" + comm.toString());
      System.out.println("Commuser---" + comm.getUser().toString());
    }
  }
Example #3
0
 private void updateTopicTime(int _topicid, String _updatetime) {
   Topic topic = new Topic();
   try {
     topic = bm.loadTopicById(_topicid);
   } catch (ClassNotFoundException e) {
     e.printStackTrace();
   } catch (SQLException e) {
     e.printStackTrace();
   }
   topic.setLastupdate(_updatetime);
   try {
     bm.update(topic);
   } catch (ClassNotFoundException e) {
     e.printStackTrace();
   } catch (SQLException e) {
     e.printStackTrace();
   }
 }
Example #4
0
  public String topicsdelete() {
    String delTopicId = this.request.getParameter("topicid");
    System.out.println("topicid=" + delTopicId);
    List<Comment> topiccomments = new ArrayList<Comment>();

    if (delTopicId != null && delTopicId.length() > 0) {
      try {
        topiccomments = bm.loadCommentsByTopicId(Integer.parseInt(delTopicId));
      } catch (NumberFormatException e) {
        e.printStackTrace();
      } catch (ClassNotFoundException e) {
        e.printStackTrace();
      } catch (SQLException e) {
        e.printStackTrace();
      }

      for (Comment comm : topiccomments) {
        System.out.println("$$$---" + comm.toString());
        try {
          bm.delete(comm);
        } catch (ClassNotFoundException e) {
          e.printStackTrace();
        } catch (SQLException e) {
          e.printStackTrace();
        }
      }

      Topic deltopic = new Topic();
      deltopic.setId(Integer.parseInt(delTopicId));
      try {
        bm.delete(deltopic);
      } catch (ClassNotFoundException e) {
        e.printStackTrace();
      } catch (SQLException e) {
        e.printStackTrace();
      }
    }
    this.listAllTopics();
    return "delete";
  }
Example #5
0
  private void listAllTopics() {
    this.topiclist = new ArrayList<Topic>();
    try {
      this.topiclist = bm.loadTopics();
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    } catch (SQLException e) {
      e.printStackTrace();
    }

    System.out.println("list size = " + this.topiclist.size());
    this.sortTopiclistByDate(this.topiclist);
  }
Example #6
0
 private void loadComment(String _commentid) {
   if (_commentid != null && _commentid.length() > 0) {
     this.comment = new Comment();
     try {
       this.comment = bm.loadCommentById(Integer.parseInt(_commentid));
     } catch (NumberFormatException e) {
       e.printStackTrace();
     } catch (ClassNotFoundException e) {
       e.printStackTrace();
     } catch (SQLException e) {
       e.printStackTrace();
     }
     System.out.println("intotopicupdate---loadComment---" + this.comment.toString());
   }
 }
Example #7
0
 private void loadTopic(String _topicid) {
   if (_topicid != null && _topicid.length() > 0) {
     this.topic = new Topic();
     try {
       this.topic = bm.loadTopicById(Integer.parseInt(_topicid));
     } catch (NumberFormatException e) {
       e.printStackTrace();
     } catch (ClassNotFoundException e) {
       e.printStackTrace();
     } catch (SQLException e) {
       e.printStackTrace();
     }
     System.out.println("intotopicupdate---loadTopic---" + this.topic.toString());
   }
 }
Example #8
0
 public String commentupdate() {
   System.out.println("--------------------commentupdate----------");
   System.out.println("commentid=" + this.binfo.getCommentid());
   System.out.println("Updated comment=" + this.binfo.getCommentcontent());
   this.comment = new Comment();
   this.loadComment(this.binfo.getCommentid());
   this.comment.setContent(this.binfo.getCommentcontent());
   try {
     bm.update(this.comment);
   } catch (ClassNotFoundException e) {
     e.printStackTrace();
   } catch (SQLException e) {
     e.printStackTrace();
   }
   //		this.alltopiclist();
   this.topic = new Topic();
   this.topic.setId(this.comment.getTopicid());
   this.topicdetail();
   return "comment_updated";
 }
Example #9
0
  public String topicbuilt() {
    System.out.println("--------------topicbuilt-----------");
    User u = new User();
    u = (User) this.request.getSession().getAttribute("user_");

    this.topic = new Topic();
    this.topic.setTitle(this.binfo.getTopictitle());
    this.topic.setContent(this.binfo.getTopiccontent());
    this.topic.setDate(CONSTANT.getNowTime());
    this.topic.setAuther(u.getId());
    this.topic.setAuthername(u.getUsername());
    this.topic.setLastupdate(this.topic.getDate());
    System.out.println("topic---------------" + this.topic.toString());
    try {
      bm.add(this.topic);
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    } catch (SQLException e) {
      e.printStackTrace();
    }
    this.alltopiclist();
    return "built";
  }