Tapestry:渲染区域时选择模型丢失

问题描述 投票:1回答:1

使用Tapestry更新选择字段上的渲染时出现问题。

我要禁用2个字段(1个文本字段和1个选择字段),具体取决于我在另一个字段(也是选择字段)中选择的内容。我想立即渲染禁用字段,因此我正在使用Tapestry Zone系统来进行渲染。

但是,当我从“ fruitOrVegetableSelect”列表中选择一个项目时,在选择字段中仍然收到以下异常:

Parameter 'model' of component fruit/Edit:fruitNames is bound to null. This parameter is not allowed to be null.

这是我在tml页面中的代码:

<t:zone t:id="fruitsForEveryOneZone" update="show">
            <tr>
                <td> <t:select
                    t:id="fruitName" t:model="fruitNames"
                    value="fruit?.fruitName" 
             disabled="getDisabledFruitField()" />
                </td>

                <td><t:textfield t:id="numberOfFruits"
                    value="fruit?.quantity"
                    disabled="getDisabledFruitField()" />
                </td>
            </tr>
</t:zone>

这是控制器中的代码:

@OnEvent(component = "fruitOrVegetableSelect", value = EventConstants.VALUE_CHANGED)
public Object updateFruitOrVegetable(Plant plant)
{
    if (plant.getName().equals("Fruit"){
        this.disabledFruitField=false;
    else {
        this.disabledFruitField=true;
    }
    return new MultiZoneUpdate("fruitsForEveryOneZone", fruitsForEveryOneZone.getBody());
} 

如果我限制区域,使其仅接受文本字段输入,则可以正常工作(除非我的选择从未被禁用)。由于某种原因,我的选择字段中的“模型”在此过程中丢失了。知道为什么会这样以及如何避免这个问题吗?

非常感谢,

问候,

tapestry
1个回答
0
投票

此代码未显示在Java类中如何声明“ fruitNames”。我猜“ fruitNames”是一个变量,只是丢失了。您应该用@Persist注释“ fruitNames”,这应该可以解决问题,或者将“ fruitNames”声明为方法(getFruitNames())。

© www.soinside.com 2019 - 2024. All rights reserved.