我在生成的列中有按钮的网格。见截图:
取决于列中的布尔值"具有Stacktrace"我想显示或隐藏按钮" view"在列#34; Stacktrace"。
我应该延伸Vaadin的com.vaadin.ui.renderers.ButtonRenderer还是有更简单的选项?
答案 0 :(得分:0)
我做了以下解决方法,但我仍然想知道如何制作按钮:
// create container
IndexedContainer container = new IndexedContainer(...);
container.addContainerProperty("stacktrace", String.class, null);
// set data
importSession.getRows().forEach(importSessionRow -> {
Item item = gpcontainer.getItem(importSessionRow.getId());
item.getItemProperty("stacktrace").setValue(importSessionRow.isHasStacktrace() ? "/admin/instrument/import/row/" + importSessionRow.getId() + "/stacktrace.html" : null);
});
// set renderer
grid.getColumn("stacktrace").setRenderer(new HtmlRenderer(),
new Converter<String, String>() {
@Override
public String convertToModel(String value,
Class<? extends String> targetType, Locale locale)
throws Converter.ConversionException {
return "not implemented";
}
@Override
public String convertToPresentation(String value,
Class<? extends String> targetType, Locale locale)
throws Converter.ConversionException {
return value != null ? "<a href='" + value + "' target='_blank'>view</a>" : null;
}
@Override
public Class<String> getModelType() {
return String.class;
}
@Override
public Class<String> getPresentationType() {
return String.class;
}
});