html (string) in table with beanitemcontainer

Hi,
how can I display html text in a table that uses beanitemcontainer as data source?
I have tried to add a generatedColumn but I should preserve the possibility of ordering

Emanuele

Hi!

If you use the same property for generated column and replace the actual property the column is still sortable (if the original column can be sorted).




    public class Bean {
        static final Random r = new Random();
        private String text = "Some text " + r.nextInt(10);
        private String html = "So<em>me</em> <strong>tex</strong>t "
                + r.nextInt(10);

        public void setHtml(String html) {
            this.html = html;
        }

        public String getHtml() {
            return html;
        }

        public void setText(String text) {
            this.text = text;
        }

        public String getText() {
            return text;
        }
    }



        Bean[] beans = new Bean[10]
;
        for (int i = 0; i < beans.length; i++) {
            beans[i]
 = new Bean();
        }

        BeanItemContainer<Bean> bc = new BeanItemContainer<Bean>(Arrays
                .asList(beans));

        Table t = new Table("Beans", bc);

        // override html column with a component, sorting as by the raw html
        // field
        t.addGeneratedColumn("html", new ColumnGenerator() {
            public Component generateCell(Table source, Object itemId,
                    Object columnId) {
                String html = ((Bean) itemId).getHtml();
                Label label = new Label(html, Label.CONTENT_XHTML);
                label.setSizeUndefined();
                return label;
            }
        });


I will try this solution as soon as possible

many thanks