Does it make sense to use Entities as JSF Backing Beans?
@Entity
@ManagedBean
@ViewScoped
public class User {
private String firstname;
private String lastname;
@EJB
private UserService service;
public void submit() {
service.create(this);
}
// ...
}
Or is it better to keep them separately and transfer the data from the backing bean to the entity at the end?
@ManagedBean
@ViewScoped
public class UserBean {
private String firstname;
private String lastname;
@EJB
private UserService service;
public void submit() {
User user = new User();
user.setFirstname(firstname);
user.setLastname(lastname);
service.create(user);
}
// ...
}
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…