关于Wicket Framework中ListView内的Button的单击功能 [英] On click functionality of Button Inside ListView in Wicket Framework

查看:88
本文介绍了关于Wicket Framework中ListView内的Button的单击功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用wicket中的ListView组件填充表.表的最后一列是按钮.因此,对于每一行,我都会在最后一列中有一个按钮.我想要实现的是单击按钮,我需要删除相应的行.因此,为此,我需要在单击按钮时获取列表的当前索引.如何实现/获得它?

Im populating a table using ListView component in wicket.The last column of my table is button. So for each row I'll have a button in the last column.What I'm trying to implement is onlick of the button I need to delete the appropriate row. So for this I need to get the current index of the list on click of button. How to achieve/get this ?

推荐答案

我将扩展Ajax按钮并在构造函数中传递行引用(项目)...然后,您可以通过覆盖onSubmit方法来执行任何所需的操作.

I would extend Ajax button and pass the row reference (item) in the constructor...then you can do anything you want..by overriding the onSubmit method

示例:

private class SpecialButton extends AjaxButton {
    final Item<Object> rowItem;

    public SpecialButton(final String id, final Item<Object> rowItem) {
        super(id);

        this.rowItem = rowItem;
    }

    @Override
    protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
        // here you cand do everything you want with the item and the model object of the item.(row)
        Object object = rowItem.getModelObject();
    }

}

您应使用收货人模型替换Item<Object>中的Object.创建此私有类后,您可以在转发器的每一行重用它.

You should replace Object from Item<Object> with your reapeater model. After creating this private class you can reuse it for every row in your repeater.

如果要删除该行,只需从用于生成转发器的列表中删除模型并刷新转发器容器(Wicket不允许通过将转发器添加到目标中来刷新转发器...而是您必须添加中继中继器.)

If you want to delete that row you just have to remove the model from the list used to generate the repeater and refresh the repeater container(Wicket does not allow you to refresh the repeater by adding it to the target...instead you have to add the repeater continer.)

这篇关于关于Wicket Framework中ListView内的Button的单击功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆