Advertisement
nex036ara

map

Feb 25th, 2014
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.47 KB | None | 0 0
  1. @ManyToMany(cascade = {ALL}, fetch = FetchType.EAGER)
  2.     @JoinTable(name = "follows",
  3.     joinColumns = { @JoinColumn(name = "userId",referencedColumnName = "user_id") },
  4.     inverseJoinColumns = { @JoinColumn(name = "zapId", referencedColumnName = "user_id") })
  5.     private List<User> follows = new ArrayList<User>();
  6.     //followed
  7.    
  8.     @ManyToMany(mappedBy = "follows",  fetch = FetchType.EAGER, cascade = {ALL})
  9.     private List<User> followers = new ArrayList<User>();
  10.  
  11.  
  12.  
  13.  
  14.  
  15. public void followUser(User toFollow) {
  16.    
  17.         if(!this.follows.contains(toFollow)) {
  18.             this.follows.add(toFollow);
  19.             toFollow.followers.add(this);
  20.         }
  21.        
  22.     }
  23.  
  24. /************** controller ****************/
  25. currentUser.followUser(authorUser);
  26.            
  27.             userDao.merge(currentUser);
  28.             userDao.merge(authorUser);
  29. User korisnik = userDao.findById(currentUser.getIdUser());
  30. request.getSession().setAttribute("korisnik",korisnik);
  31.  
  32.  
  33.  
  34.  
  35.  
  36. /************* jsp ******************* /
  37. <c:if test="${fn:length(korisnik.followers)==0}">
  38.             <h3>You currently don't have any user who follow you.</h3>
  39.         </c:if>
  40.            
  41.            
  42.        <c:if test="${fn:length(korisnik.followers)!=0}">  
  43.         <h3>You are followed by:</h3>
  44.         <table border="1" class="dataTable">       
  45.             <tr>
  46.                 <th><fmt:message key="korisnickoIme"/></th>
  47.                 <th><fmt:message key="imeKorisnika"/></th>
  48.                 <th><fmt:message key="prezimeKorisnika"/></th>
  49.             </tr>
  50.        
  51.             <c:forEach items="${korisnik.followers}" var="follower">
  52.                 <tr>
  53.                         <td>${follower.username}</td>
  54.                         <td>${follower.name}</td>
  55.                         <td>${follower.surname}</td>
  56.                         <td><a href = "AutorProfileController?idFollower=${follower.idUser}&idPage=1"><fmt:message key="prikazi"/></a></td>
  57.                 </tr>
  58.             </c:forEach>
  59.        
  60.         </table>
  61.     </c:if>
  62.        
  63.         <br>
  64.        
  65.        
  66.        
  67.         <c:if test="${fn:length(korisnik.follows)==0}">
  68.             <h3>You currently don't have any followed users.</h3>
  69.         </c:if>
  70.        
  71.        
  72.         <c:if test="${fn:length(korisnik.follows)!=0}">
  73.             <h3>You currently follow:</h3>
  74.             <table border="1" class="dataTable">       
  75.             <tr>
  76.                 <th><fmt:message key="korisnickoIme"/></th>
  77.                 <th><fmt:message key="imeKorisnika"/></th>
  78.                 <th><fmt:message key="prezimeKorisnika"/></th>
  79.                
  80.             </tr>
  81.            
  82.             <c:forEach items="${korisnik.follows}" var="foll">
  83.             <tr>
  84.                 <td>${foll.username}</td>
  85.                 <td>${foll.name}</td>
  86.                 <td>${foll.surname}</td>
  87.                 <td><a href = "AutorProfileController?idFollowed=${foll.idUser}&idPage=1"><fmt:message key="prikazi"/></a></td>         </tr>
  88.             </c:forEach>
  89.         </table>
  90.         </c:if>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement