Tapestry组件对象持久性问题

时间:2013-06-20 18:19:08

标签: tapestry

我创建了一个我在表单中使用的组件。

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd">
<noscript class="js-required">
    ${message:javascript_required}
</noscript>
<t:content>
    <table>
        <tr>
            <h2>Vehicle:</h2>
        </tr>
        <tr>

            <td>
                VRM:
            </td>
            <td>
                    <input t:type="TextField" t:value="vehicle.vrm" t:id="vrmTextField" t:validate="minlength=3,maxlength=15" size="30"/>

            </td>
        </tr>
    </table>
</t:content>

和java

公共类VehicleComponent {

@Property
Vehicle vehicle;

VehicleComponent() {
    vehicle = new Vehicle();
}

public void clear() {
    vehicle = new Vehicle();

}
}

问题是在我提交此组件所属的表单之后,文本字段中的值保留 - 我希望它从字段中清除。我使用Sting,int等属性的其他更简单的组件都清除。

componentResources.discardPersistentFieldChanges()不对车辆组件起作用,也不直接调用上面的clear方法。我觉得如果我要将@persist添加到车辆对象中,那么componentResources.discardPersistentFieldChanges()就可以了 - 但我不能因为你无法实例化一个@ persist-ed对象。如果我删除@Property然后我得到一个空指针。

有关如何在持久化后从组件中的字段清除对象值的任何建议?我唯一的选择是首先使用@Persist捕获值,然后在提交时构建对象,如果我想清除组件字段?

1 个答案:

答案 0 :(得分:0)

您可以尝试在vehicle = new Vehicle();中设置onSuccessFromForm()。 或者,您可以将vehicle.vrm更改为vehicle?.vrm,然后在vehicle = null中设置onSuccessFromForm()

相关问题