将值传递给方法onSucces

时间:2017-05-05 16:55:07

标签: java tapestry tml

我在java中使用tapestry,我在tml文件中有一个循环,每行都有一个按钮。单击按钮时,我需要将行中元素的值传递给onSuccess()方法。 我用t:context =" value"尝试了它。在按钮中,但它不起作用,我找不到解决方案。

TML:

<tr t:type="Loop" t:source="movieList" t:value="movie">
    <td>
        <a href="#" t:type="PageLink" t:page="index">
            ${movie.title}
        </a>
    </td>
    <td>
        ${movie.score}
    </td>
    <td>
        <form t:type="Form" class="form-horizontal" t:id="deleteMovie">
            <button type="submit" t:context="movie.movieId" class="btn btn-primary">
                <img src="${context:i/basura.png}" width="25" heigth="25"/>
            </button>
        </form>
    </td>
</tr>

Java方法:

 @OnEvent(value = "success", component ="deleteMovie")
 Object[] onSuccesFromDeleteMovie(Long movieId) throws InstanceNotFoundException {
     movieService.removeMovie(movieId);
     return new Object[] {startIndex};
 }

1 个答案:

答案 0 :(得分:0)

It "doesn't work" because your button is a plain HTML button, not a Tapestry component. In this case t:context will be rendered as a plain HTML attribute, you can verify that by inspecting resulted HTML.

To let Tapestry know that your button is actually a Tapestry Submit component, you can add the t: prefix to the type attribute, i.e.:

<button t:type="submit" t:context="movie.movieId" ... />

Foreseeing your next question: returning Object[] from an event handler won't work because it's not a supported method return value.

对于这样一个简单的用例,您可以在上下文中使用普通EventLink,您不必提交表单来触发服务器端事件处理程序。

如果您决定在某个时候使用Ajax,也许这个JumpStart's AjaxFormLoop example会有所帮助。