JPAContainer在表中添加组件?

时间:2014-05-14 14:33:51

标签: java vaadin7

我正在寻找如何在我的表中添加组件。我的表使用JPAContainer作为数据源。我正在尝试使用addContainerProperty但不起作用并返回异常。

我正在尝试这个

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());

现在有效!

1 个答案:

答案 0 :(得分:0)

将UI组件添加到选择组件(Table,Tree,TreeTable,ComboBox,...)的数据源是您的问题的错误方法。 Table组件的容器数据源仅包含表的数据模型,而不包含将显示此数据的组件。

因此,不是向JPAContainer添加属性(在内部处理其属性时不允许使用此容器),而是使用com.vaadin.ui.TableFieldFactory为表设置自定义Table.setTableFieldFactory(TableFieldFactory fieldFactory)