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

pon*_*zao 5 java ajax tapestry

我有一个Zone内部 a FormZone它更新了一个包含输入字段的块,我想将其绑定到 parent Form。不幸的是,这似乎并不像我希望的那么容易,因为我收到了以下错误消息。

The Description component must be enclosed by a Form component. [at classpath:...Page.tml, line 100]
Run Code Online (Sandbox Code Playgroud)

源代码的简化版本.tml如下。

The Description component must be enclosed by a Form component. [at classpath:...Page.tml, line 100]
Run Code Online (Sandbox Code Playgroud)

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

Hen*_*ing 4

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

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

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

在您的 TML 中:

<div t:type="FormInjector" t:id="injector" position="below" />
Run Code Online (Sandbox Code Playgroud)

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

$('theClientIdOfMyFormInjector').trigger();
Run Code Online (Sandbox Code Playgroud)

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

组件类:

@Inject
private Block formFieldsBlock;

@OnEvent(component = "injector")
Block loadExtraFormFields() {
    return this.formFieldsBlock;
}
Run Code Online (Sandbox Code Playgroud)