How can dependent lookups implemented in cuba 7. All examples i can find is only using datasource from cuba 6.
And this is not working for edit screen.
https://doc.cuba-platform.com/manual-7.0/gui_data_comp_dep.html
Thanks
How can dependent lookups implemented in cuba 7. All examples i can find is only using datasource from cuba 6.
And this is not working for edit screen.
https://doc.cuba-platform.com/manual-7.0/gui_data_comp_dep.html
Thanks
Hi,
Why do you think so? Are there any technical details?
I have two entity AAQMS and AAQMSParameter with 1-n relation. In entity AAQMSData both are attribute with n-1 relation. In cuba 6plus with datasource “=:ds$----” will define the dependent lookup, but in cuba 7 plus datasource is not being used. If I user":AAQMS" as parameter as given in link then it notify error that “AAQMS” is not defined parameter.
IllegalStateException: Query argument aaqms not found in the list of parameters provided during query execution.
AAQM Entity
public class AAQMS extends StandardEntity {
@NotNull
@Column(name = "NAME", nullable = false, length = 50)
protected String name;
@Lookup(type = LookupType.DROPDOWN, actions = {"lookup", "clear"})
@NotNull
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "COMPLEX_ID")
protected Complex complex;
@Column(name = "LATITUDE")
protected Integer latitude;
@Column(name = "LONGITUDE")
protected Integer longitude;
@Composition
@OnDelete(DeletePolicy.CASCADE)
@OneToMany(mappedBy = "aAQMS")
protected List<AAQMSParameter> parameter;
public Complex getComplex() {
return complex;
}
public void setComplex(Complex complex) {
this.complex = complex;
}
public List<AAQMSParameter> getParameter() {
return parameter;
}
public void setParameter(List<AAQMSParameter> parameter) {
this.parameter = parameter;
}
public Integer getLongitude() {
return longitude;
}
public void setLongitude(Integer longitude) {
this.longitude = longitude;
}
public Integer getLatitude() {
return latitude;
}
public void setLatitude(Integer latitude) {
this.latitude = latitude;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
AAQMSParameter Entity
package com.company.sheeloffice.entity;
import com.haulmont.chile.core.annotations.NamePattern;
import com.haulmont.cuba.core.entity.StandardEntity;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
@NamePattern("%s, %s|parameter,aAQMS")
@Table(name = "SHEELOFFICE_AAQMS_PARAMETER")
@Entity(name = "sheeloffice_AAQMSParameter")
public class AAQMSParameter extends StandardEntity {
@NotNull
@Column(name = "PARAMETER_", nullable = false, length = 50)
protected String parameter;
@Column(name = "TARGET_TYPE")
protected String targetType;
@Column(name = "LOW_STANDARD")
protected Double lowStandard;
@Column(name = "HIGH_STANDARD")
protected Double highStandard;
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "A_AQMS_ID")
protected AAQMS aAQMS;
@NotNull
@Column(name = "UNIT", nullable = false, length = 20)
protected String unit;
AAQMSData Entity
package com.company.sheeloffice.entity;
import com.haulmont.cuba.core.entity.StandardEntity;
import com.haulmont.cuba.core.entity.annotation.Lookup;
import com.haulmont.cuba.core.entity.annotation.LookupType;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.util.Date;
@Table(name = "SHEELOFFICE_AAQMS_DATA")
@Entity(name = "sheeloffice_AAQMSData")
public class AAQMSData extends StandardEntity {
@Temporal(TemporalType.DATE)
@NotNull
@Column(name = "DATE_", nullable = false)
protected Date date;
@Lookup(type = LookupType.DROPDOWN, actions = {"lookup", "clear"})
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "AAQMS_ID")
protected AAQMS aaqms;
@Lookup(type = LookupType.DROPDOWN, actions = {"lookup", "clear"})
@NotNull
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "PARAMETER_ID")
protected AAQMSParameter parameter;
@NotNull
@Column(name = "VALUE_", nullable = false)
protected Double value;
@Column(name = "COMPLIANCE", length = 5)
protected String compliance;
How to solve this issue
Thanks
I am able to solve the problem of “No parameter” by using below code
//@LoadDataBeforeShow
public class AAQMSDataEdit extends StandardEditor<AAQMSData> {
@Inject
private CollectionLoader<AAQMS> aaqmsesLc;
@Inject
private CollectionLoader<AAQMSParameter> parametersLc;
@Subscribe
private void onBeforeShow(BeforeShowEvent event) {
aaqmsesLc.load();
}
@Subscribe(id = "aaqmsesDc", target = Target.DATA_CONTAINER)
private void onAaqmsesDcItemChange(InstanceContainer.ItemChangeEvent<AAQMS> event) {
parametersLc.setParameter("myaaqms", event.getItem());
parametersLc.load();
}
and removing
@LoadDataBeforeShow
But now edit button is showing blank screen when editing the AAQMSData,
if I use @LoadDataBeforeShow then paramter is not passed and if i remove it editing data doesnot work
I think the problem is solved by using @LoadBeforeShow and following code:
@Subscribe
private void onBeforeShow(BeforeShowEvent event) {
aaqmsesLc.load();
parametersLc.setParameter("myaaqms", null);
}
@Subscribe(id = "aaqmsesDc", target = Target.DATA_CONTAINER)
private void onAaqmsesDcItemChange(InstanceContainer.ItemChangeEvent<AAQMS> event) {
parameterField.clear();
parametersLc.setParameter("myaaqms", event.getItem());
parametersLc.load();
}
Is this solution is perfect. Any suggestions
Thanks
This is almost exactly as explained in the docs: Dependencies Between Data Components.
But parametersLc.setParameter("myaaqms", null); looks superfluous.
The example cited is for two tables. I am doing this in edit screen. If I remove this line then following error is generated while creating new data
IllegalStateException: Query argument myaaqms not found in the list of parameters provided during query execution.
Secondly example ask for removal of @LoadDataBeforeShow but I have to keep it otherwise, if I edit data then no data will appear.
The above changes are trial & error result to get the dependent lookup work in both create/edit screen. (I have again checked the by removing these two additional changes (from example) and getting above problems
thanks and regards
Umesh