lookupPickerField 中的动态数据

Dynamic data in lookupPickerField

我在屏幕上显示了 screen and the screen controller. There are two lookupPickerField 个组件。

一个简单的任务 - 当其中第一个 (PK) 的值发生变化时,第二个应该加载依赖值 (FK)。

我的屏幕描述符:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<window xmlns="http://schemas.haulmont.com/cuba/window.xsd"
        caption="msg://editCaption"
        class="com.tkbbank.client.web.item.CardItemEdit"
        datasource="cardItemDs"
        focusComponent="fieldGroup"
        messagesPack="com.tkbbank.client.web.item">

     <dsContext>
        <datasource id="cardItemDs" class="com.tkbbank.client.entity.CardItem" allowCommit="false"/>
            <collectionDatasource id="cardTypeDs" class="com.tkbbank.client.entity.CardType" view="_local">
            <query>
                <![CDATA[select e from demo$CardType e]]>
            </query>
        </collectionDatasource>
            <collectionDatasource id="cardSubTypeDs" class="com.tkbbank.client.entity.CardSubType" view="_local">
            <query>
                <![CDATA[select s from demo$CardSubType s where s.cardType.id = :component$cardSubTypePicker.id]]>
            </query>
        </collectionDatasource>
    </dsContext>

    <dialogMode forceDialog="true" width="AUTO"/>
    <layout expand="windowActions" spacing="true">
        <fieldGroup id="fieldGroup" datasource="cardItemDs">
            <column width="500px">

                <field id="cardType" caption="Тип документа">
                    <lookupPickerField id="cardTypePicker" optionsDatasource="cardTypeDs"/>
                </field>
                <field id="cardSubType" caption="Подтип документа">
                    <lookupPickerField id="cardSubTypePicker" optionsDatasource="cardSubTypeDs"/>
                </field>

                // Skipped

我的屏幕控制器:

public class CardItemEdit extends AbstractEditor<CardItem> {

    @Inject
    private Datasource<CardItem> cardItemDs;

    @Inject
    private Metadata metadata;

    @Inject
    private CollectionDatasource<CardSubType, UUID> cardSubTypeDs;

    @Inject
    private LookupPickerField cardTypePicker;

    @Override
    public void init(Map<String, Object> params) {
        CardItem cardItem = metadata.create(CardItem.class);
        cardItemDs.setItem(cardItem);

        cardTypePicker.addValueChangeListener(e -> cardSubTypeDs.refresh());
    }
}

实体CardSubType:

@NamePattern("Подтип входящего документа: %s |subtype")
@Table(name = "DEMO_CARD_SUB_TYPE")
@Entity(name = "demo$CardSubType")
public class CardSubType extends StandardEntity {
    private static final long serialVersionUID = -3558412722346178348L;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "CARD_TYPE_ID")
    protected CardType cardType;

    // Skipped

所以,我select一个值在cardTypePicker,但是第二个组件仍然是空的。两个表都有数据。

可能是什么问题?

如果能提供信息,我将不胜感激。感谢大家。

Mario David answered this question here.

谢谢你,马里奥!

使用以下屏幕数据源,所有下拉菜单都可以正常工作:

 <dsContext>
    <datasource id="cardItemDs" class="com.tkbbank.client.entity.CardItem" allowCommit="false" view="card-item-view"/>
        <collectionDatasource id="cardTypeDs" class="com.tkbbank.client.entity.CardType">
        <query>
            <![CDATA[select e from demo$CardType e]]>
        </query>
    </collectionDatasource>
        <collectionDatasource id="cardSubTypeDs" class="com.tkbbank.client.entity.CardSubType">
        <query>
            <![CDATA[select s from demo$CardSubType s where s.cardType.id = :ds$cardTypeDs]]>
        </query>
    </collectionDatasource>
</dsContext>