Ok I know I can do this because I've seen it work before.
Basically, I make a getter method in one of my classes such a that the method doesn't have an associated class variable.
For example
@Entity
public class Customer implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue
private Integer customerID;
@NaturalId
private String name;
@OneToMany(mappedBy = "customerID", cascade = CascadeType.ALL, orphanRemoval = true)
private List<CustomerAddress> customerAddressList;
.
.
.
public CustomerAddress getMainAddress(){
//Calculations to retrieve the customer's main/default/primary address
//from the List, customerAddressList.
}
While I haven't tried this in Thymeleaf (but intend to do so soon), I do know in Wicket I can use property expressions to access the main address of a customer (which I think is interesting because there is no variable called mainAddress
in the Customer class).
That being said, is this use of getters is considered an acceptable practice?