How to use inheritance in ManagedBeans?

1

Considering:

public abstract class Usuario {
    public Usuario(String login, String senha) {
        this.login = login;
        this.senha = senha;
    }
    private String login;
    private String senha;
}
public class Professor extends Usuario {
    public Professor(String login, String senha, String cpf) {
        super(login, senha);
        this.cpf = cpf;
    }
    private String cpf;
}
public class Aluno extends Usuario {
    public Aluno(String login, String senha, String matricula) {
        super(login, senha);
        this.matricula = matricula;
    }
    private String matricula;
}

How could I transform the subclasses above into ManagedBeans and how would I get the values coming from the view to the attributes of the superclass? I know that putting only the @ManagedBean annotation in the subclasses will not work.

The main reason for this is that both the teacher and the student will log in to the same form and the filter ( javax.servlet.Filter ) must receive a Usuario to avoid boilerplates in the filter itself and subclasses, / p>

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
   Usuario u = (Usuario)((HttpServletRequest)request).getSession().getAttribute("usuario");
    if (usuario != null && usuario.isAutorizado()) {
        chain.doFilter(request, response);
    }
    else {
        String contextPath = ((HttpServletRequest)request).getContextPath();
        ((HttpServletResponse)response).sendRedirect(contextPath + "login.jsf");
    }
}
    
asked by anonymous 20.03.2015 / 02:50

0 answers