如何在wicket框架中的表中添加图像列? [英] How can I add an image column to a table in wicket framework?

查看:40
本文介绍了如何在wicket框架中的表中添加图像列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在检票口框架的表的每个单元格中添加一个包含图像的列.我在Java类中制作表,并具有如下的createColumns()方法:

I want to add a column containing images in each cell of a table in wicket framework. I make the table in a java class and have a createColumns() method as the following:

private List<IColumn> createColumns() {
    List<IColumn> columns = new ArrayList<IColumn>();
    // Create the columns that will be displayed, second param is the sort
    // order
    // Use column position for aggregate functions
    // Otherwise the query uses column aliases so these need to match here

    columns.add(new PropertyColumn(new Model("Status"), "code") {
        private static final long serialVersionUID = 1L;
        @Override
        public void populateItem(Item item, String componentId, IModel model) {
            Object[] values = ((ArrayWrapper) model.getObject()).getArray();
            setStatus((Integer) values[0]);
            item.add(new Image(componentId, new ResourceReference(this.getClass(), getStatus())));
        }
    });

    columns.add(new PropertyColumn(new Model("First"), "2", "array[1]"));
    columns.add(new PropertyColumn(new Model("Last"), "3", "array[2]"));        
    columns.add(new PropertyColumn(new Model("Sender"), "sender",
            "array[4]"));
    columns.add(new PropertyColumn(new Model("Receiver"), "receiver",
            "array[5]"));

    columns.add(new HeaderlessColumn() {
        private static final long serialVersionUID = 1L;

        public void populateItem(Item cellItem, String componentId,
                IModel rowModel) {
            cellItem.add(new ActionPanel(componentId, rowModel));
        };
    });

    return columns;
}

html文件如下所示:

The html file is simply as the following:

<html xmlns:wicket="http://wicket.sourceforge.net/">
<body>
<wicket:extend>
 <table align="center" wicket:id="results"></table>
</wicket:extend>
</body>
</html>

但是我得到一个例外:

org.apache.wicket.markup.MarkupException:组件单元必须应用于类型为'img'的标签,而不是''(第0行,第0列)

org.apache.wicket.markup.MarkupException: Component cell must be applied to a tag of type 'img', not '' (line 0, column 0)

这与我创建图像列的行有关.谁能帮我做到这一点?

And it's related to the lines that I make the column for image. Can anyone help me how I can make it?

推荐答案

CreateColumns方法中的代码如下:

The code in CreateColumns method is as the following:

   columns.add(new PropertyColumn(new Model("Status"), "code") {
        private static final long serialVersionUID = 1L;
        @Override
        public void populateItem(Item item, String componentId, IModel model) {
            Object[] values = ((ArrayWrapper) model.getObject()).getArray();
            setStatus((Integer) values[0]);
            item.add(new ImagePanel(componentId, new ResourceReference(SearchResults.class, getStatus())));
        }
    });

这是ImagePanel:

And this is the ImagePanel:

 public class ImagePanel extends Panel {
    private static final long serialVersionUID = 1L;
    /**
     * @param id
     */
    public ImagePanel(String id, ResourceReference image) {
        super(id);
        add(new Image("status", image));
    }
}

该面板的html代码为:

The html code for the panel is:

<html xmlns:wicket="http://wicket.sourceforge.net/">
<body>
<wicket:panel>
<img wicket:id="status"/>
</wicket:panel>
</body>
</html>

这篇关于如何在wicket框架中的表中添加图像列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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