Tapestry 5.2:使用表单中的数据更新区域
我正在使用 Tapestry 5.2.4 和 AJAX。
在我的 Test.tml 中,我有一个表单:
<form t:id="form">
<t:label for="userName"/>:
<input t:type="TextField" t:id="userName" size="30"/>
</form>
和一个显示变量“test”的区域:
<t:zone t:id="myZone" id="myZone">
<p>show test ${test}</p>
</t:zone>
现在我尝试将表单字段“userName”的值放入带有操作链接的区域中:
<t:actionlink t:id="SomeLink" zone="myZone" context="${userName}">update</t:actionlink>
这是 java 类 Test.java:
public class Test {
@Persist
@Property
private String userName;
@Property
private String test;
@InjectComponent
private Zone myZone;
@Component
private Form form;
Object onActionFromSomeLink(String input) {
test = input;
return myZone.getBody();
}
}
我认为这会“获取”表单字段 userName 的值,并将其与 actionlink 一起传递给 onActionFromSomeLink 方法。该方法将变量“test”设置为输入并显示该区域。
这不起作用并引发一个我不明白的错误:
Ajax failure: Status 500 for /example/test.somelink
: Request event 'action' (on component Test:somelink) was not handler;您必须在组件或其容器之一中提供匹配的事件处理程序方法。
Communication with the server failed: Request event 'action' (on component Test:somelink) was not handled; you must provide a matching event handler method in the component or in one of its containers.
如何实现一个函数,从表单获取输入然后更新区域?
干杯
I'm playing with tapestry 5.2.4 and AJAX.
In my Test.tml I have a form:
<form t:id="form">
<t:label for="userName"/>:
<input t:type="TextField" t:id="userName" size="30"/>
</form>
And a zone that displays the variable "test":
<t:zone t:id="myZone" id="myZone">
<p>show test ${test}</p>
</t:zone>
Now I try to put the value of the form field "userName" into the zone with an actionlink:
<t:actionlink t:id="SomeLink" zone="myZone" context="${userName}">update</t:actionlink>
Here's the java class Test.java:
public class Test {
@Persist
@Property
private String userName;
@Property
private String test;
@InjectComponent
private Zone myZone;
@Component
private Form form;
Object onActionFromSomeLink(String input) {
test = input;
return myZone.getBody();
}
}
I thought this would "take" the value of the form field userName and pass it with an actionlink to the method onActionFromSomeLink. The method sets the variable "test" to input and the zone is displayed.
This does not work and throws an error I do not understand:
Ajax failure: Status 500 for /example/test.somelink
: Request event 'action' (on component Test:somelink) was not handled; you must provide a matching event handler method in the component or in one of its containers.
Communication with the server failed: Request event 'action' (on component Test:somelink) was not handled; you must provide a matching event handler method in the component or in one of its containers.
How can I implement a function, that takes input from a form and then updates a zone?
Cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您使用了错误的组件。
ActionLink
呈现 HTML 链接,它根本不与表单交互。虽然您可以为链接提供上下文
,但它是绝对静态的,并且不会从客户端的表单中检索值。 (context
主要用于区分对象,如果您在某处有一个项目列表,每个项目都有一个对它们执行某些操作的链接。)您要做的是提交表单并获得该表单更新您的区域。您必须将
zone
参数添加到表单组件,并添加一些可以让您提交表单的内容:在您的类中:
如果您确实想使用链接来提交表单,则
LinkSubmit
组件也可以让您做到这一点。You're using the wrong component. An
ActionLink
renders an HTML link, it does not at all interact with forms. While you can provide acontext
to the link, it is absolutely static and does not retrieve values from forms on the client side. (context
is useful mainly to discriminate between objects if you have a list of items somewhere with a link each that does something to them.)What you're trying to do is to submit the form and have that update your zone. You'll have to add the
zone
parameter to the form component, and add something that lets you submit the form:And in your class:
If you really want to use a link to submit the form, the
LinkSubmit
component lets you do that, too.