Polymorphism should be done in a model rather than in a representation.
eg.
<h:inputText value="#{person.login}" />
with
public interface Person {
public void login();
}
and
public class Student implements Person {
public void login() {
}
}
and
public class Lecturer implements Person {
public void login() {
}
}
and finally in a managed bean
private Person person;
public String login() {
if (isStudent) person = new Student();
if (isLecturer) person = new Lecturer();
person.login();
return "home";
}
Otherwise, you need to change the view every time you add / remove another type Person. It is not right.
source
share