Facebook
From Coral Leech, 5 Years ago, written in Java.
Embed
Download Paste or View Raw
Hits: 217
  1. package controller;
  2.  
  3. import java.io.Serializable;
  4. import java.util.ArrayList;
  5. import java.util.Date;
  6. import java.util.List;
  7. import javax.enterprise.context.SessionScoped;
  8. import javax.inject.Inject;
  9. import javax.inject.Named;
  10. import javax.validation.Validation;
  11. import model.Comment;
  12. import model.Offer;
  13. import model.Order1;
  14. import model.UserAccount;
  15. import service.impl.CommentServiceImpl;
  16. import service.impl.OfferServiceImpl;
  17. import service.impl.UserAccountServiceImpl;
  18.  
  19. @Named("commentController")
  20. @SessionScoped
  21. public class CommentController implements Serializable {
  22.  
  23.     private String commentText;
  24.     private List<Comment> commentList;
  25.     private int selectedCommentIndex;
  26.     private int commentId;
  27.     private String offerCommentText;
  28.     private Offer selectedOffer = new Offer();
  29.     private Comment selectedComment = new Comment();
  30.     private int oldValue;
  31.     private int currentValue;
  32.     private Offer offerId;
  33.  
  34.     @Inject
  35.     private CommentServiceImpl commentService;
  36.  
  37.     @Inject
  38.     private OfferServiceImpl offerService;
  39.  
  40.     @Inject
  41.     private UserAccountServiceImpl userAccountService;
  42.  
  43.     @Inject
  44.     private OfferController offerController;
  45.  
  46.     public String getCommentText() {
  47.         return commentText;
  48.     }
  49.  
  50.     public void setCommentText(String commentText) {
  51.         this.commentText = commentText;
  52.     }
  53.  
  54.     public List<Comment> getCommentList() {
  55.         return commentList;
  56.     }
  57.  
  58.     public void setCommentList(List<Comment> commentList) {
  59.         this.commentList = commentList;
  60.     }
  61.  
  62.     public int getSelectedCommentIndex() {
  63.         return selectedCommentIndex;
  64.     }
  65.  
  66.     public void setSelectedCommentIndex(int selectedCommentIndex) {
  67.         this.selectedCommentIndex = selectedCommentIndex;
  68.     }
  69.  
  70.     public Integer getCommentId() {
  71.         return commentId;
  72.     }
  73.  
  74.     public void setCommentId(Integer commentId) {
  75.         this.commentId = commentId;
  76.     }
  77.  
  78.     public String getOfferCommentText() {
  79.         return offerCommentText;
  80.     }
  81.  
  82.     public void setOfferCommentText(String offerCommentText) {
  83.         this.offerCommentText = offerCommentText;
  84.     }
  85.  
  86.     public Offer getSelectedOffer() {
  87.         return selectedOffer;
  88.     }
  89.  
  90.     public void setSelectedOffer(Offer selectedOffer) {
  91.         this.selectedOffer = selectedOffer;
  92.     }
  93.  
  94.     public OfferServiceImpl getOfferService() {
  95.         return offerService;
  96.     }
  97.  
  98.     public void setOfferService(OfferServiceImpl offerService) {
  99.         this.offerService = offerService;
  100.     }
  101.  
  102.     public int getOldValue() {
  103.         return oldValue;
  104.     }
  105.  
  106.     public void setOldValue(int oldValue) {
  107.         this.oldValue = oldValue;
  108.     }
  109.  
  110.     public int getCurrentValue() {
  111.         return currentValue;
  112.     }
  113.  
  114.     public void setCurrentValue(int currentValue) {
  115.         this.currentValue = currentValue;
  116.     }
  117.  
  118.     public CommentServiceImpl getCommentService() {
  119.         return commentService;
  120.     }
  121.  
  122.     public void setCommentService(CommentServiceImpl commentService) {
  123.         this.commentService = commentService;
  124.     }
  125.  
  126.     public UserAccountServiceImpl getUserAccountService() {
  127.         return userAccountService;
  128.     }
  129.  
  130.     public void setUserAccountService(UserAccountServiceImpl userAccountService) {
  131.         this.userAccountService = userAccountService;
  132.     }
  133.  
  134.     public Offer getOfferId() {
  135.         return offerId;
  136.     }
  137.  
  138.     public void setOfferId(Offer offerId) {
  139.         this.offerId = offerId;
  140.     }
  141.  
  142.     // sprwdzanie czy użytkonik ma jakąś ofertę
  143. //     public void initCommentData() {
  144. //        UserAccount loggedUser = userAccountService.getLoggedUser();
  145. //        if (loggedUser != null) {
  146. //            if (!FacesContext.getCurrentInstance().isPostback()) {
  147. //                offerToAdd = commentService.get();
  148. //            }
  149. //        }
  150. //    }
  151.     public void addComment() {
  152.         Comment commentToBeAdded = selectedComment;
  153.         Offer offerId = offerController.getSelectedOffer();
  154.         UserAccount user = userAccountService.getLoggedUser();
  155.         commentToBeAdded.setCommentText(commentText);
  156.         commentToBeAdded.setCommentCreatingTime(new Date());
  157.         commentToBeAdded.setCommentId(commentId);
  158.         commentToBeAdded.setUserId(user);
  159.         commentToBeAdded.setOfferId(offerId);
  160.         commentService.create(commentToBeAdded);
  161.     }
  162.  
  163.  
  164. }
  165.