简体   繁体   English

在Tapestry 5中更新表单内的区域

[英]Updating a zone inside a form in Tapestry 5

I've got a Zone inside a Form , the Zone is updated with a block containing input fields which I would like to bind to the parent Form . 我在一个Form有一个ZoneZone更新了一个包含输入字段的块,我想将其绑定到父Form Unfortunately this doesn't seem to work quite as easily as I hoped as I am greeted with the following error message. 不幸的是,这似乎并不像我希望的那样容易,因为我收到以下错误消息。

The Description component must be enclosed by a Form component. [at classpath:...Page.tml, line 100]

A simplified version of the source .tml is below. .tml简化版本如下。

<t:form t:id="editForm" t:context="item.id">
    <table>
        <tr>
            <th>Name</th>
            <td><t:textField value="item.name"/></td>
        </tr>
        <t:block t:id="block">
            <tr class="person">
                <th>Description</th>
                <td><t:textField t:id="description" value="item.description"/></td>
            </tr>
         </t:block>
         <t:zone t:id="itemZone" id="itemZone"/>
         <t:actionlink t:id="item" zone="itemZone">Click me!</t:actionlink>
    </table>
</t:form>

Is there a way to do the binding and if not what other alternatives are there? 是否有办法进行绑定,如果没有其他替代方案?

This answer is outdated, you can add form elements using the usual zone functionality from Tapestry 5.2 on . 这个答案已经过时,您可以使用Tapestry 5.2上的常用区域功能添加表单元素。 This method still works as well, though. 不过,这种方法仍然有效。

Original answer, valid for Tapestry 5.0 and 5.1: 原始答案,对Tapestry 5.0和5.1有效:

The FormInjector component allows you to add form elements to an exising form. FormInjector组件允许您将表单元素添加到exising表单。 You will have to write some custom JS to trigger the form injection, though. 但是,您必须编写一些自定义JS来触发表单注入。

In your TML: 在你的TML中:

<div t:type="FormInjector" t:id="injector" position="below" />

You can trigger the injection in your JS code like this: 您可以在JS代码中触发注入,如下所示:

$('theClientIdOfMyFormInjector').trigger();

You can find the injector DIV inside your form by its class name ( myForm.down('div.t-forminjector') ). 您可以通过类名( myForm.down('div.t-forminjector') )在表单中找到注入器DIV。

The component class: 组件类:

@Inject
private Block formFieldsBlock;

@OnEvent(component = "injector")
Block loadExtraFormFields() {
    return this.formFieldsBlock;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM