0

I am new To Vaadin, I have created a Table and i can able to populate the data in that through the BeanItemCOntainer, bellow is the code for this.

public Component getMainContent(ViewChangeListener.ViewChangeEvent event) {
        List<ExecutionPlanVO> executionPlanVOs = executionPlanDelegate.getExecutionPlans(getSearchVO());
        Table table = new Table();
        BeanItemContainer<ExecutionPlanVO> container = new BeanItemContainer<ExecutionPlanVO>(ExecutionPlanVO.class, executionPlanVOs);
        container.addBean(new ExecutionPlanVO());
        table.setContainerDataSource(container);
        table.setVisibleColumns(
                new Object[] {"billOfladingNo" , "containerNo" , "houseBill" , "carrier" , "customer" , "origin" , "pol" , "transshipment" ,
                        "pod" , "destination" , "start" , "completion" , "status"});
        table.setColumnHeaders(
                new String[] {"Bill Of Lading" , "Container No." , "House Bill" , "Carrier" , "Customer" , "Origin" , "POL" , "Transshipment" ,
                        "POD" , "Destination" , "Start (LT)" , "Completion (LT)" , "Status"});
        table.setStyleName("ep-list-table");
        return table;

    }

I Have two questions here, 1. I would want to change billOfladingNo column as a link, which will permorm some action when i click ? 2. i wanted to add one more column with couple of link Icons?

can you help me how can i add the columns ?

Thanks in advance Kiran.

Kiran
  • 69
  • 1
  • 9

2 Answers2

0

You can Create a class to implement ColumnGenerator to return the link and the icon. I have done a sample below

class Linker implements ColumnGenerator{

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    @Override
    public Object generateCell(Table source, Object itemId, Object columnId) {
        // TODO Auto-generated method stub

        Item item = source.getItem(itemId);
        Link link = new Link();
        String linkCaption = item.getItemProperty("billOfladingNo").toString();
        link.setCaption(linkCaption);
        link.setResource(new ExternalResource("http:/www.domain.com/"+linkCaption));
        return link;
    }



}

class LinkIcons implements ColumnGenerator{

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    @Override
    public Object generateCell(Table source, Object itemId, Object columnId) {
        // TODO Auto-generated method stub

        Label icons = new Label();
        icons.setIcon(FontAwesome.LINK);
        return icons;
    }
}
    table.addGeneratedColumn("billOfLading", new Linker());
table.addGeneratedColumn("link", LinkIcons);

be sure to make your billoflading from the bean invisible and add the generated column ids to the table visible ids.

mumbasa
  • 632
  • 7
  • 11
-1

Depends what vaadin version Your using if 7.X.X then:

You can set on the container what type is the chosen column:

container.addContainerProperty("billOfladingNo", new Link, null);

1st parameter is the property of Your column

2nd is the type You want to have

3rd is the default value

that will make Your column type: com.vaadin.ui.Link

to make a new Link with possible navigation:

        Link link = new Link("CAPTION", new ExternalResource("URL"));

For the second question u need to set the link caption to accept HTML and then set the FontAwesome icon html:

    link.setCaptionAsHtml(true);
    link.setCaption(FontAwesome.ANCHOR.getHtml());
Athi
  • 527
  • 5
  • 10