Hello
I want do select categories for my products so I created a category entity. I want to have a tree inside the category editor so I can visually select the hierarchy. Now, I am not able to have the tree item preselected when I want to edit an item. I managed to get IllegalStateException: Datasource doesn’t contain items, although the Tree shows datasource items
Please help
Entity
@NamePattern("%s|nume")
@Table(name = "SPICA_PRODUS_CATEGORIE")
@Entity(name = "spica$ProdusCategorie")
public class ProdusCategorie extends StandardEntity {
private static final long serialVersionUID = 1264937965825142240L;
@Column(name = "NUME")
protected String nume;
@Lookup(type = LookupType.DROPDOWN, actions = {"lookup"})
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "CATEGORIE_ID")
protected ProdusCategorie categorie;
public ProdusCategorie getCategorie() {
return categorie;
}
public void setCategorie(ProdusCategorie categorie) {
this.categorie = categorie;
}
public void setNume(String nume) {
this.nume = nume;
}
public String getNume() {
return nume;
}
}
XML editor
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<window xmlns="http://schemas.haulmont.com/cuba/window.xsd"
caption="msg://editorCaption"
class="com.company.spica.web.produscategorie.ProdusCategorieEdit"
datasource="produsCategoriesDs"
focusComponent="fieldGroup"
messagesPack="com.company.spica.web.produscategorie">
<dsContext>
<datasource id="produsCategoriesDs"
class="com.company.spica.entity.ProdusCategorie"
view="produsCategorie-view"/>
<collectionDatasource id="categoriesDs"
class="com.company.spica.entity.ProdusCategorie"
view="_minimal">
<query>
<![CDATA[select e from spica$ProdusCategorie e]]>
</query>
</collectionDatasource>
<hierarchicalDatasource id="produsCategoriesDsH"
class="com.company.spica.entity.ProdusCategorie"
hierarchyProperty="categorie"
view="produsCategorie-view">
<query>
<![CDATA[select e from spica$ProdusCategorie e]]>
</query>
</hierarchicalDatasource>
</dsContext>
<dialogMode height="600"
width="800"/>
<layout expand="windowActions"
spacing="true">
<fieldGroup id="fieldGroup"
datasource="produsCategoriesDs">
<column width="250px">
<field id="nume"/>
<field id="categorie"
optionsDatasource="categoriesDs"/>
</column>
</fieldGroup>
<tree id="treeCat"
height="200px"
width="300px">
<treechildren datasource="produsCategoriesDsH"/>
</tree>
<frame id="windowActions"
screen="editWindowActions"/>
</layout>
</window>
and Controller
public class ProdusCategorieEdit extends AbstractEditor<ProdusCategorie> {
@Inject
private Tree<ProdusCategorie> treeCat;
@Named("fieldGroup.categorie")
private LookupPickerField categorieField;
@Override
public void init(Map<String, Object> params) {
super.init(params);
}
@Override
protected void postInit() {
super.postInit();
treeCat.expandUpTo(3); //now working
treeCat.setCaption("bau"); //working
treeCat.setSelected(getItem().getCategorie()); //not working - IllegalStateException: Datasource doesn't contain items
}
}
Thank you