You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Cuba平台LookupPickerField联动加载数据失败求助

Troubleshooting Dependent LookupPickerField in CUBA Platform

Let's walk through the issues in your code and fix the dependent picker field problem step by step.

1. Critical Query Parameter Mistake

The most obvious error is in your cardSubTypeDs query. You're referencing the second picker's ID instead of the first one:

<!-- Wrong parameter: uses cardSubTypePicker instead of cardTypePicker -->
<query>
    <![CDATA[select s from demo$CardSubType s where s.cardType.id = :component$cardSubTypePicker.id]]>
</query>

Since cardSubTypePicker is empty initially (and stays empty until data loads), this query will always return no results. You need to point it to the first picker:

<!-- Corrected query -->
<collectionDatasource id="cardSubTypeDs" class="com.tkbbank.client.entity.CardSubType" view="_minimal">
    <query>
        <![CDATA[select s from demo$CardSubType s where s.cardType.id = :component$cardTypePicker.id]]>
    </query>
</collectionDatasource>

2. Fix the View for CardSubType

Notice I changed the view from _local to _minimal in the above code. Here's why:

  • The _local view for StandardEntity only includes system fields (like id, createTs) but does not load your business field subtype.
  • Your CardSubType uses subtype in its @NamePattern, so the lookup picker needs this field to display options. Without it, even if data is loaded, the picker will appear empty.

If _minimal doesn't include subtype (depends on your entity setup), create a custom view:

@View(name = "cardSubType-view", properties = {"id", "subtype", "cardType"})
@Entity(name = "demo$CardSubType")
public class CardSubType extends StandardEntity {
    // ... your existing code
}

Then use it in the datasource:

<collectionDatasource id="cardSubTypeDs" class="com.tkbbank.client.entity.CardSubType" view="cardSubType-view">

3. Optimize the Value Change Listener

Your current listener refreshes the datasource, but it's good practice to clear the second picker's value when the first picker changes (to avoid invalid selections):

@Override
public void init(Map<String, Object> params) {
    CardItem cardItem = metadata.create(CardItem.class);
    cardItemDs.setItem(cardItem);
    
    cardTypePicker.addValueChangeListener(e -> {
        // Clear the subtype picker to remove old invalid values
        cardSubTypePicker.setValue(null);
        // Refresh the subtype datasource with the new cardType value
        cardSubTypeDs.refresh();
    });
}

4. Additional Verification Steps

If the above fixes don't work, check these:

  • Database Integrity: Ensure the DEMO_CARD_SUB_TYPE table has rows where CARD_TYPE_ID matches existing IDs in DEMO_CARD_TYPE.
  • CardType Datasource: Confirm cardTypeDs is loading all CardType records correctly (check if the first picker has options).
  • Enable SQL Logging: Turn on Hibernate SQL logging to see the actual query executed. Add this to your persistence.xml:
    <property name="hibernate.show_sql" value="true"/>
    <property name="hibernate.format_sql" value="true"/>
    
    This will let you verify if the correct cardType.id parameter is being passed to the cardSubTypeDs query.

These changes should resolve the issue where the second picker stays empty after selecting a value in the first one.

内容的提问来源于stack exchange,提问作者anon

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 08:51:46