我是Vaadin的新手,我创建了一个表,我可以通过BeanItemCOntainer填充数据,下面是代码。
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;
}
我这里有两个问题, 1.我想将billOfladingNo列更改为链接,当我点击时它将会暂停一些操作? 2.我想添加一个带有几个链接图标的列?
你可以帮助我如何添加列?
提前致谢 基兰。
答案 0 :(得分:0)
您可以创建一个类来实现ColumnGenerator以返回链接和图标。我在下面做了一个示例
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);
请务必使bean中的billoflading不可见,并将生成的列ID添加到表可见的ID中。
答案 1 :(得分:-1)
取决于你使用的vaadin版本7.X.X然后:
您可以在容器上设置所选列的类型:
container.addContainerProperty("billOfladingNo", new Link, null);
第一个参数是您的列的属性
第二个是您想拥有的类型
第3是默认值
将使您的列类型为:com.vaadin.ui.Link
使用可能的导航制作新链接:
Link link = new Link("CAPTION", new ExternalResource("URL"));
对于第二个问题,您需要设置链接标题以接受HTML,然后设置FontAwesome图标html:
link.setCaptionAsHtml(true);
link.setCaption(FontAwesome.ANCHOR.getHtml());