I have recently started studying JSF and have stumbled accross the following two ways to include entities into a Controller Managed bean. One by direct injection with the entity as a ManagedBean
, the other with the entity as a non-managed bean simply as an instance variable which is initialized at @PostConstruct
.
What are the advantages/disadvantages of one way or another? The second is usually showed as the "right way" however it seems that it's more complicated to maintain.
Non-Managed Entity
@Entity
public class Book {
//...attributes
}
@ManagedBean
public class BookController {
private Book book;
@PostConstruct
public void init() {
book = new Book();
}
}
Managed Entity
@Entity
@ManagedBean
public class Book implements Serializable {
//...attributes
}
@ManagedBean
public class BookController {
@ManagedProperty(name="#{customer}")
private Book book;
}