Place all the fields in a class, also called the essence of the class or DTO (eg User, Product, Orderetc.) and refer to it. These can be JDBC / JPA objects. Put all the business methods in your class, also called service or domain object (eg UserService, ProductServiceetc.), and instead refers to it. It could be EJB.
eg. so not
public class Bean {
private Long id;
private String field1;
private String field2;
private String field3;
@PostConstruct
public void init() {
}
public void save() {
}
}
But moreover
public class Bean {
private Long id;
private Entity entity;
@EJB
private EntityService service;
@PostConstruct
public void init() {
entity = service.find(id);
}
public void save() {
service.save(entity);
}
}
In addition, I also saw code in which nested objects / entities are delegated via additional getters / setters in a bean, for example,
private Entity entity;
public String getField1() {
return entity.getField1();
}
public void setField1(String field1) {
entity.setField1(field1);
}
This is completely unnecessary. One getter is sufficient for an entity (a setter is optional!) In conjunction with
<h:inputText value="#{bean.entity.field1}" />
. . street, houseNumber, zipCode, city, country of User /DTO Address User.
, (, Netbeans + Woodstock). , , , .