Mar*_*sse 2 java ajax tapestry
我正在玩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>
Run Code Online (Sandbox Code Playgroud)
以及显示变量"test"的区域:
<t:zone t:id="myZone" id="myZone">
<p>show test ${test}</p>
</t:zone>
Run Code Online (Sandbox Code Playgroud)
现在我尝试将表单字段"userName"的值放入带有actionlink的区域中:
<t:actionlink t:id="SomeLink" zone="myZone" context="${userName}">update</t:actionlink>
Run Code Online (Sandbox Code Playgroud)
这是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();
}
}
Run Code Online (Sandbox Code Playgroud)
我认为这将"获取"表单字段userName的值,并通过actionlink将其传递给onActionFromSomeLink方法.该方法将变量"test"设置为输入,并显示区域.
这不起作用,并抛出一个我不明白的错误:
Ajax失败:状态500 /example/test.somelink:未处理请求事件'action'(在组件Test:somelink上); 您必须在组件或其中一个容器中提供匹配的事件处理程序方法.
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.
Run Code Online (Sandbox Code Playgroud)
如何实现一个从表单输入然后更新区域的函数?
干杯
你使用的是错误的组件.一个ActionLink显示的HTML链接,它不会在所有形式的互动.虽然您可以提供context链接,但它绝对是静态的,并且不会从客户端的表单中检索值.(context主要用于区分对象,如果你有一个带有链接的项目列表,每个链接都对它们做了什么.)
您要做的是提交表单并更新您的区域.您必须将zone参数添加到表单组件,并添加允许您提交表单的内容:
<form t:id="form" t:zone="myZone">
<t:label for="userName"/>:
<input t:type="TextField" t:id="userName" size="30"/>
<input type="submit" t:type="Submit" />
</form>
Run Code Online (Sandbox Code Playgroud)
在你的班上:
@Inject
private Request request;
@OnEvent(EventConstants.SUCCESS)
Object formSubmitted(){
//return zone content only if AJAX request, page otherwise
if (request.isXHR()) {
return myZone.getBody();
} else {
return this;
}
}
Run Code Online (Sandbox Code Playgroud)
如果您真的想使用链接提交表单,那么该LinkSubmit组件也可以让您这样做.
| 归档时间: |
|
| 查看次数: |
4687 次 |
| 最近记录: |