Вопрос по tokenList. Есть сущность “Клиент”, есть сущность “Сервис”. Не получается добавить сервисы к клиенту, используя сущность-связь. В выпадающем списке пусто, хотя сервисы существуют.
Создаю сущность “Клиент”:
@NamePattern("%s|login")
@Table(name = "CUBANCC_CUSTOMER")
@Entity(name = "cubancc_Customer")
public class Customer extends StandardEntity {
private static final long serialVersionUID = -5697805039520197433L;
@Column(name = "login")
private String login;
@Column(name = "name")
private String name;
@Column(name = "phone")
private String phone;
@Column(name = "city")
private String city;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "street_id")
protected Streets street;
@Composition
@OnDelete(DeletePolicy.CASCADE)
@OneToMany(mappedBy = "customer")
protected Set<CustomerService> services;
@Column(name = "build")
private String build;
@Column(name = "flat")
private String flat;
@Column(name = "comments")
private String comments;
@Column(name = "credit")
private Double credit;
@Column(name = "deposit")
private Double deposit;
@Column(name = "email")
private String email;
@Column(name = "uid")
private Integer uid;
@Column(name = "password")
private String password;
@Column(name = "pin")
private String pin;
@Column(name = "contract")
private String contract;
@Column(name = "contract_date")
private Date contract_date;
@Column(name = "document")
private String document;
@Column(name = "document_date")
private Date document_date;
@Column(name = "document_grant")
private String document_grant;
public String getComments() {
return comments;
}
public void setComments(String comments) {
this.comments = comments;
}
public Double getCredit() {
return credit;
}
public void setCredit(Double credit) {
this.credit = credit;
}
public Double getDeposit() {
return deposit;
}
public void setDeposit(Double deposit) {
this.deposit = deposit;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public Integer getUid() {
return uid;
}
public void setUid(Integer uid) {
this.uid = uid;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getPin() {
return pin;
}
public void setPin(String pin) {
this.pin = pin;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public Streets getStreet() {
return street;
}
public void setStreet(Streets street) {
this.street = street;
}
public String getBuild() {
return build;
}
public void setBuild(String build) {
this.build = build;
}
public String getFlat() {
return flat;
}
public void setFlat(String flat) {
this.flat = flat;
}
public String getLogin() {
return login;
}
public void setLogin(String login) {
this.login = login;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getContract() {
return contract;
}
public void setContract(String contract) {
this.contract = contract;
}
public Date getContract_date() {
return contract_date;
}
public void setContract_date(Date contract_date) {
this.contract_date = contract_date;
}
public String getDocument() {
return document;
}
public void setDocument(String document) {
this.document = document;
}
public Date getDocument_date() {
return document_date;
}
public void setDocument_date(Date document_date) {
this.document_date = document_date;
}
public String getDocument_grant() {
return document_grant;
}
public void setDocument_grant(String document_grant) {
this.document_grant = document_grant;
}
public Set<CustomerService> getServices() {
return services;
}
public void setServices(Set<CustomerService> services) {
this.services = services;
}
}
Создаю сущность “Сервис”:
@NamePattern("%s|name")
@Table(name = "CUBANCC_SERVICE")
@Entity(name = "cubancc_Service")
public class Service extends StandardEntity {
private static final long serialVersionUID = -685777450665421950L;
@Column(name = "name")
protected String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Создаю сущность-связку:
@NamePattern("%s|service")
@Table(name = "CUBANCC_CUSTOMER_SERVICE")
@Entity(name = "cubancc_CustomerService")
public class CustomerService extends StandardEntity {
private static final long serialVersionUID = -133808369760654851L;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "customer_id")
protected Customer customer;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "service_id")
protected Service service;
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
public Service getService() {
return service;
}
public void setService(Service service) {
this.service = service;
}
}
Экран редактирования клиента:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<window xmlns="http://schemas.haulmont.com/cuba/screen/window.xsd"
caption="msg://customerEdit"
focusComponent="form"
messagesPack="group.indev.cubancc.web.screens.customer">
<data>
<instance id="customerDc"
class="group.indev.cubancc.customer.Customer"
view="customer-edit">
<loader/>
<collection id="customerServiceDc" property="services"/>
</instance>
<collection id="streetsDc"
class="group.indev.cubancc.streets.Streets"
view="_minimal">
<loader id="streetsDl">
<query>
<![CDATA[select e from cubancc_Streets e]]>
</query>
</loader>
</collection>
<collection id="servicesDc"
class="group.indev.cubancc.customerservice.CustomerService"
view="_local">
<loader id="servicesDl">
<query>
<![CDATA[select e from cubancc_CustomerService e]]>
</query>
</loader>
</collection>
</data>
<dialogMode height="600"
width="800"/>
<layout expand="editActions" spacing="true">
<form id="form" dataContainer="customerDc">
<column width="250px">
<textField id="uidField" property="uid" editable="false"/>
<textField id="loginField" property="login" required="true"/>
<passwordField id="passwordField" property="password" required="true"/>
<textField id="pinField" property="pin" editable="false"/>
<textField id="nameField" property="name" required="true"/>
<textField id="depositField" property="deposit" editable="false"/>
<textField id="creditField" property="credit"/>
<textField id="phoneField" property="phone" required="true"/>
<textField id="emailField" property="email"/>
<lookupPickerField dataContainer="customerDc"
property="street"
optionsContainer="streetsDc"
required="true"/>
<textField id="buildField" property="build"/>
<textField id="flatField" property="flat"/>
<textField id="contractField" property="contract"/>
<dateField id="contractDateField" property="contract_date"/>
<textField id="documentField" property="document"/>
<dateField id="documentDateField" property="document_date"/>
<textField id="documentGrantField" property="document_grant"/>
<textField id="commentsField" property="comments"/>
<tokenList id="userServiceList" dataContainer="customerDc"
property="services"
clearEnabled="false"
inline="true">
<lookup optionsContainer="servicesDc" lookup="true"/>
</tokenList>
</column>
</form>
<hbox id="editActions" spacing="true">
<button action="windowCommitAndClose"/>
<button action="windowClose"/>
</hbox>
</layout>
</window>
views.xml:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<views xmlns="http://schemas.haulmont.com/cuba/view.xsd">
<view entity="cubancc_Streets" name="street-edit-view" extends="_local"/>
<view entity="cubancc_Customer" name="customer-browse-view" extends="_local">
<property name="street" view="_local"/>
</view>
<view entity="cubancc_Customer" name="customer-edit" extends="_local">
<property name="street" view="_local"/>
<property name="services" view="_local"/>
</view>
<view entity="cubancc_CustomerService" name="customer-with-service" extends="_local"/>
</views>