我有实体客户(代表数据库中的表):
@Entity
public class Customer implements Serializable {
private static final long serialVersionUID = 1L;
@Id
private int nr;
private String firstname;
private String lastname;
@ManyToMany
@JoinTable(
name = "ACCES",
joinColumns = {
@JoinColumn(name = "CUSTOMER_NR", referencedColumnName = "NR")
},
inverseJoinColumns = {
@JoinColumn(name = "ROOM_ROOMID", referencedColumnName = "ROOMID")
}
)
private List<Room> rooms;
}
我是实体室(代表数据库中的表):
@Entity
public class Room implements Serializable {
private static final long serialVersionUID = 1L;
@Id
private int roomId;
private String building;
private String roomnr;
@ManyToMany(mappedBy = "rooms")
private List<Customer> customer;
这些表有多对多的关系。
在我的JSF页面上,我有一个显示所有客户的表格。使用selectBooleanCheckbox我想在生成的连接表中创建/删除(选中/取消选中复选框)条目。
<h:form>
<h:panelGrid rendered="#{!empty roomController.allRooms}">
<h:dataTable value="#{raumController.alleRooms}" var="r" border="1">
<h:column>
<f:facet name="header">
<h:outputText value="Raum-Id" />
</f:facet>
<h:outputLabel value="#{r.raumId}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Building" />
</f:facet>
<h:outputLabel value="#{r.building}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="roomnr" />
</f:facet>
<h:outputLabel value="#{r.roomnr}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Access" />
</f:facet>
<h:selectBooleanCheckbox onclick="this.form.submit()" value="#{customerController.AccessCheck(r.raumId)}" immediate="true" valueChangeListener="#{customerController.accessChanged}">
<f:attribute name="raumId" value="#{r.raumId}" />
</h:selectBooleanCheckbox>
</h:column>
</h:dataTable>
</h:panelGrid>
</h:form>
如果每个客户都有权访问一个房间并且页面上显示正确的状态,我怎样才能让每个客户都有自己的条目呢?