Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @ManyToMany(cascade = {ALL}, fetch = FetchType.EAGER)
- @JoinTable(name = "follows",
- joinColumns = { @JoinColumn(name = "userId",referencedColumnName = "user_id") },
- inverseJoinColumns = { @JoinColumn(name = "zapId", referencedColumnName = "user_id") })
- private List<User> follows = new ArrayList<User>();
- //followed
- @ManyToMany(mappedBy = "follows", fetch = FetchType.EAGER, cascade = {ALL})
- private List<User> followers = new ArrayList<User>();
- public void followUser(User toFollow) {
- if(!this.follows.contains(toFollow)) {
- this.follows.add(toFollow);
- toFollow.followers.add(this);
- }
- }
- /************** controller ****************/
- currentUser.followUser(authorUser);
- userDao.merge(currentUser);
- userDao.merge(authorUser);
- User korisnik = userDao.findById(currentUser.getIdUser());
- request.getSession().setAttribute("korisnik",korisnik);
- /************* jsp ******************* /
- <c:if test="${fn:length(korisnik.followers)==0}">
- <h3>You currently don't have any user who follow you.</h3>
- </c:if>
- <c:if test="${fn:length(korisnik.followers)!=0}">
- <h3>You are followed by:</h3>
- <table border="1" class="dataTable">
- <tr>
- <th><fmt:message key="korisnickoIme"/></th>
- <th><fmt:message key="imeKorisnika"/></th>
- <th><fmt:message key="prezimeKorisnika"/></th>
- </tr>
- <c:forEach items="${korisnik.followers}" var="follower">
- <tr>
- <td>${follower.username}</td>
- <td>${follower.name}</td>
- <td>${follower.surname}</td>
- <td><a href = "AutorProfileController?idFollower=${follower.idUser}&idPage=1"><fmt:message key="prikazi"/></a></td>
- </tr>
- </c:forEach>
- </table>
- </c:if>
- <br>
- <c:if test="${fn:length(korisnik.follows)==0}">
- <h3>You currently don't have any followed users.</h3>
- </c:if>
- <c:if test="${fn:length(korisnik.follows)!=0}">
- <h3>You currently follow:</h3>
- <table border="1" class="dataTable">
- <tr>
- <th><fmt:message key="korisnickoIme"/></th>
- <th><fmt:message key="imeKorisnika"/></th>
- <th><fmt:message key="prezimeKorisnika"/></th>
- </tr>
- <c:forEach items="${korisnik.follows}" var="foll">
- <tr>
- <td>${foll.username}</td>
- <td>${foll.name}</td>
- <td>${foll.surname}</td>
- <td><a href = "AutorProfileController?idFollowed=${foll.idUser}&idPage=1"><fmt:message key="prikazi"/></a></td> </tr>
- </c:forEach>
- </table>
- </c:if>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement