极其常见的任务。不,你不想要多对多,这意味着同一个约会应该有多个客户。尝试类似:
豆:
private Long clientId;
private Date date;
private List<Client> clients;
public List<Client> getClients(){
if(clients == null){
clients = clientDAO.findAll(); // Lazy loading since JSF has a habit of calling the getter multiple times.
}
return clients;
}
// Getters and setters for client and date
public void saveAppointment(){
applicationDAO.createAppointment(date, clientId);
}
xhtml:
<h:selectOneMenu value="#{bean.clientId}">
<f:selectItems value="#{bean.clients}" var="client" itemLabel="#{client.name]" itemValue="#{client.id}"/>
</h:selectOneMenu>