0
我正在尋找如何在我的表中添加組件。我的表使用JPAContainer作爲數據源。我試圖使用addContainerProperty,但不起作用並返回一個異常。JPAContainer在表中添加組件?
我想這
private final CustomJPAContainer<Curriculum> datasource = new CustomJPAContainer<Curriculum>(Curriculum.class);
Button btnView = new Button();
Table tabela = new Table("",datasource);
tabela.addContainerProperty("View", Button.class, null);
//exception
java.lang.UnsupportedOperationException
at com.vaadin.addon.jpacontainer.JPAContainer.addContainerProperty(JPAContainer.java:666)
at com.vaadin.ui.AbstractSelect.addContainerProperty(AbstractSelect.java:806)
at com.vaadin.ui.Table.addContainerProperty(Table.java:4260)
at br.ind.ibg.views.VisualizarCurriculum.buildLayout(VisualizarCurriculum.java:58)
at br.ind.ibg.views.VisualizarCurriculum.<init>(VisualizarCurriculum.java:36)
at br.ind.ibg.utils.MenuSistema$1.menuSelected(MenuSistema.java:60)
at com.vaadin.ui.MenuBar.changeVariables(MenuBar.java:186)
at com.vaadin.server.communication.ServerRpcHandler.changeVariables(ServerRpcHandler.java:396)
at com.vaadin.server.communication.ServerRpcHandler.handleBurst(ServerRpcHandler.java:221)
at com.vaadin.server.communication.ServerRpcHandler.handleRpc(ServerRpcHandler.java:111)
at com.vaadin.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:91)
at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:37)
at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1382)
at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:238)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
任何想法?
/** *編輯/ 我解決了這個問題,使用setGeneratedColumn()
在這裏,我是怎麼做。
public class ButtonColumnGenerator implements Table.ColumnGenerator{
private static final long serialVersionUID = 1L;
@Override
public Object generateCell(Table source, Object itemId, Object columnId) {
Property prop = source.getItem(itemId).getItemProperty(columnId);
Button btnView = new Button();
btnView.setData(itemId);
btnView.setDescription("Curriculum: " + itemId);
btnView.setIcon(new ThemeResource("../icons/eye.png"));
btnView.setWidth("20px");
btnView.setHeight("20px");
btnView.setStyleName(Reindeer.BUTTON_LINK);
return btnView;
}
}
/*** my app */
Button btnView = new Button();
Table tabela = new Table("",datasource);
tabela.setVisibleColumns(new Object[]{"idCurriculum", "nome", "cpf"});
tabela.setColumnHeaders(new String[] {"#", "Nome", "Cpf"});
tabela.addGeneratedColumn("", new ButtonColumnGenerator());
now works!
我編輯了我找到的解決方案的帖子。我確實使用setGeneratedColumn()來解決我的問題。謝謝! – FernandoPaiva