Note that there are some explanatory texts on larger screens.

plurals
  1. POManaged Bean inheritance
    primarykey
    data
    text
    <p>I wish to have make a super class for a few managed beans, containing amongst other things an injected @SessionScoped managed bean, and an @EJB. The following works</p> <p>Super class: </p> <pre><code>@ManagedBean @ViewScoped public abstract class UserPageController implements Serializable { private static final long serialVersionUID = -6118448960678133445L; @ManagedProperty(value = "#{sessionController}") protected SessionController sessionController; private User user; private String userId; @EJB protected UserBean userBean; public UserPageController() { } public SessionController getSessionController() { return sessionController; } public void setSessionController(SessionController sessionController) { this.sessionController = sessionController; } //-------------------------------- User ------------------------------------ public String getUserId() { return userId; } public void setUserId(String userId) { this.userId = userId; } public User getUser() { if (user == null) { if (getUserId() != null &amp;&amp; sessionController.getLoggedInUser().getRole().isManager()) { User dbUser = userBean.findUser(Long.parseLong(userId)); if (dbUser != null) { setUser(dbUser); } } else { setUser(userBean.findUser(sessionController.getLoggedInUser().getId())); } } return user; } public void setUser(User user) { this.user = user; } } </code></pre> <p>Usage:</p> <pre><code>@ManagedBean @ViewScoped public class UserCompetenceController extends UserPageController implements Serializable { // Stuff that uses sessionController &amp; userBean. } </code></pre> <p>Is there any way to avoid annotating the abstract super class as a managed bean? It somehow feels wrong, but without it, dependency injection won't work.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload