【问题标题】:Updating a zone inside a form in Tapestry 5在 Tapestry 5 中更新表单内的区域
【发布时间】:2010-06-03 14:13:46
【问题描述】:

我在Form 中有一个ZoneZone 更新为包含我想绑定到父Form 的输入字段的块。不幸的是,这似乎不像我希望的那样容易,因为我收到了以下错误消息。

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

.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>

有没有办法进行绑定,如果没有,还有其他选择吗?

【问题讨论】:

    标签: java ajax tapestry


    【解决方案1】:

    此答案已过时,您可以使用通常的区域功能 from Tapestry 5.2 on 添加表单元素。不过,这种方法仍然有效。

    原始答案,适用于 Tapestry 5.0 和 5.1:

    FormInjector 组件允许您将表单元素添加到现有表单。不过,您将不得不编写一些自定义 JS 来触发表单注入。

    在您的 TML 中:

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

    您可以像这样在您的 JS 代码中触发注入:

    $('theClientIdOfMyFormInjector').trigger();
    

    您可以通过类名 (myForm.down('div.t-forminjector')) 在表单中找到注入器 DIV。

    组件类:

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

    【讨论】:

    • 您是否知道我可以即时更改上下文信息?我目前正在通过 t:context="item.id" 向后端传递一个 id,但我无法找到可以动态更改它的位置。
    • @Ponzao:对不起...改变在哪里做什么? (也许这会是一个很好的新问题?)
    • 是的,我会提出一个新问题,请稍等。
    • 我添加了一个新问题stackoverflow.com/questions/2974282/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-03
    • 1970-01-01
    • 2014-03-03
    • 2021-12-22
    相关资源
    最近更新 更多