RapidClipse,XdevTable没有显示数据,但是数据仍在容器中怎么了?

时间:2019-07-28 13:34:40

标签: java vaadin7 rapidclipse

我试图通过在RapidClipse4中使用本机查询来生成交叉表。 收集了数据,并且在控制台上的输出仍然可用,但是分配给xDevTable无效。 我创建了以下代码:

private void button_buttonClick(final Button.ClickEvent event) {

        try {
            final String selJahr = this.cmbJahr.getSelectedItem().getBean().getJahr();
            final StringBuilder sb = new StringBuilder();
            sb.append("select FLOOR(RAND() * 999999) as rid, l1_Id as `l1id`, l1_GroupName as `l1GroupName`, l2_Id as `l2id`, l2_GroupName as `l2GroupName`, ");
            sb.append("sum( case when (monat = 1) then dbetrag end ) AS `Jan`, ");
            sb.append("sum( case when monat = 2 then dbetrag end ) AS `Feb`, ");
            sb.append("sum( case when monat = 3 then dbetrag end ) AS `Mrz`, ");
            sb.append("sum( case when monat = 4 then dbetrag end ) AS `Apr`, ");
            sb.append("sum( case when monat = 5 then dbetrag end ) AS `Mai`, ");
            sb.append("sum( case when monat = 6 then dbetrag end ) AS `Jun`, ");
            sb.append("sum( case when monat = 7 then dbetrag end ) AS `Jul`, ");
            sb.append("sum( case when monat = 8 then dbetrag end ) AS `Aug`, ");
            sb.append("sum( case when monat = 9 then dbetrag end ) AS `Sep`, ");
            sb.append("sum( case when monat = 10 then dbetrag end ) AS `Okt`, ");
            sb.append("sum( case when monat = 11 then dbetrag end ) AS `Nov`, ");
            sb.append("sum( case when monat = 12 then dbetrag end ) AS `Dez`, ");
            sb.append("sum(dbetrag) as `Sum` ");
            sb.append("from V_HibCrosUmsGiroOpaOmaReport ");
            sb.append("where  jahr='2019' and konto_Id in ('7,8') ");
            sb.append("group by l1_Id, l1_GroupName, l2_Id, l2_GroupName; ");

            final String sqlq = sb.toString();
            final EntityManagerFactory emf = Persistence.createEntityManagerFactory("RC_07");
            final EntityManager em = emf.createEntityManager();

            System.out.print( "SQL String: " + sqlq + "/n");

            final Query q = em.createNativeQuery(sqlq);
            // will be later used:
            //q.setParameter(1, selJahr);
            //q.setParameter(2, "7,8");
            // final List<VUmsCrosstbl> VUmsCrosstbl = q.getResultList();


            final XdevBeanItemContainer<VUmsCrosstbl> myContainer = new XdevBeanItemContainer<>(VUmsCrosstbl.class);
            myContainer.addAll(q.getResultList());

            this.tblUmsCross.setContainerDataSource(myContainer);
            this.tblUmsCross.setVisibleColumns(VUmsCrosstbl_.rid.getName(),VUmsCrosstbl_.l1Id.getName(),VUmsCrosstbl_.l1GroupName.getName(),VUmsCrosstbl_.l2Id.getName(),VUmsCrosstbl_.l2GroupName.getName(),VUmsCrosstbl_.jan.getName(),VUmsCrosstbl_.feb.getName(),VUmsCrosstbl_.mrz.getName(),VUmsCrosstbl_.apr.getName(),VUmsCrosstbl_.mai.getName(),VUmsCrosstbl_.jun.getName(),VUmsCrosstbl_.jul.getName(),VUmsCrosstbl_.aug.getName(),VUmsCrosstbl_.sep.getName(),VUmsCrosstbl_.okt.getName(),VUmsCrosstbl_.nov.getName(),VUmsCrosstbl_.dez.getName(),VUmsCrosstbl_.sum.getName());
            this.tblUmsCross.setId(VUmsCrosstbl_.rid.getName());
            this.tblUmsCross.setColumnHeaders(new String[] {"rid", "l1_Id", "l1_GroupName", "l2_Id", "l2_GroupName", "Jan","Feb","Mrz","Apr","Mai","Jun","Jul","Aug","Sep","Okt","Nov","Dez", "Sum"});
            this.tblUmsCross.addItems(q.getResultList());
            this.tblUmsCross.getBeanContainerDataSource().refresh();


            final List<Object[]> VUmsCrosstbl = q.getResultList();
            for (final Object[] a : VUmsCrosstbl) {
                System.out.println("Ds: " + a[0] + " " + a[1] + " " + a[2] + " " + a[3] + " " + a[4] + " " + a[5] + " " + a[6] + " " + a[7] + " " + a[8] + " " + a[9] + " " + a[10] + " " + a[11] + " " + a[12] + " " + a[13] + " " + a[14] + " " + a[15]);
            }

            em.close();

        } catch (final Exception e) {
            e.printStackTrace();
            Notification.show("Do isch was falsch bei button_buttonClick  ", e.getMessage(),
                    Notification.Type.ERROR_MESSAGE);
        }

    }

该过程运行无误 代码“ System.out.println(“ Ds:...”)末尾的行仅用于检查容器是否有数据。 这些行将在控制台上准确输出预期的输出和所有预期的数据

在应用程序中,仍然创建并显示列(标头),但没有包含数据的行。单元格是空的。

我的错误在哪里/我错了什么? 任何想法/帮助将不胜感激。

我想,您还应该知道:

我在查询中使用的表名不同于实体名称“ VUmsCrosstbl”

为什么?

我使用的实体名称“ VUmsCrosstbl”是一个db视图,它完全包含了我作为查询结果集而得到的字段。

有了这个技巧,我可以使用Rapidclipse中的实体生成器,它会自动生成实体和dao。

对于我在查询中使用的视图V_HibCrosUmsGiroOpaOmaReport,月份名称Jan-Dez仍然不在我第一次使用的实体或dao中,并产生了另一个错误。

先谢谢您 rgds OpaHeinz

1 个答案:

答案 0 :(得分:0)

我自己找到了解决方案:

1)我仍然不确定为什么上面的代码不起作用,我只能假设分配过程中有问题:


    myContainer.addAll(q.getResultList()); 

要使其正常工作,我更改了DAU并放置了以下代码:


            public List<VUmsCrosstbl> getAllCrossDataforYearKonto2 ()
    {  //final String pjahr, final String pKontoIDs

        final StringBuilder sb = new StringBuilder();
                sb.append("select FLOOR(RAND() * 999999) as rid, l1_Id, L1_GroupName, l2_Id, L2_GroupName, ");
                sb.append("sum( case when (monat = 1) then dbetrag end ) AS `Jan`, ");
                sb.append("sum( case when monat = 2 then dbetrag end ) AS `Feb`, ");
                sb.append("sum( case when monat = 3 then dbetrag end ) AS `Mrz`, ");
                sb.append("sum( case when monat = 4 then dbetrag end ) AS `Apr`, ");
                sb.append("sum( case when monat = 5 then dbetrag end ) AS `Mai`, ");
                sb.append("sum( case when monat = 6 then dbetrag end ) AS `Jun`, ");
                sb.append("sum( case when monat = 7 then dbetrag end ) AS `Jul`, ");
                sb.append("sum( case when monat = 8 then dbetrag end ) AS `Aug`, ");
                sb.append("sum( case when monat = 9 then dbetrag end ) AS `Sep`, ");
                sb.append("sum( case when monat = 10 then dbetrag end ) AS `Okt`, ");
                sb.append("sum( case when monat = 11 then dbetrag end ) AS `Nov`, ");
                sb.append("sum( case when monat = 12 then dbetrag end ) AS `Dez`, ");
                sb.append("sum(dbetrag) as `Sum` ");
                sb.append("from V_HibCrosUmsGiroOpaOmaReport ");
                sb.append("where  jahr= ? and konto_Id in ( ? ) ");
                sb.append("group by l1_Id, L1_GroupName, l2_Id, L2_GroupName; ");
                final String sqlq = sb.toString();


        final Query nativeQuery = em().createNativeQuery(sqlq, VUmsCrosstbl.class);
        nativeQuery.setParameter(1, "2019");
        nativeQuery.setParameter(2, "7,8");
        final List<VUmsCrosstbl> resultList = nativeQuery.getResultList();

        return resultList;
    }

然后我在按钮的click事件中使用了此函数,将结果分配到XDevBeanitemContainer和表中:


        private void button_buttonClick(final Button.ClickEvent event) {

            final XdevBeanItemContainer<VUmsCrosstbl> myContainer = new XdevBeanItemContainer<>(VUmsCrosstbl.class);
            myContainer.addAll(new VUmsCrosstblDAO().getAllCrossDataforYearKonto2());

            this.tblUmsCross.setContainerDataSource(myContainer);
            this.tblUmsCross.setId(VUmsCrosstbl_.rid.getName());
            this.tblUmsCross.setVisibleColumns(VUmsCrosstbl_.rid.getName(),VUmsCrosstbl_.l1Id.getName(),VUmsCrosstbl_.l1GroupName.getName(),VUmsCrosstbl_.l2Id.getName(),VUmsCrosstbl_.l2GroupName.getName(),VUmsCrosstbl_.jan.getName(),VUmsCrosstbl_.feb.getName(),VUmsCrosstbl_.mrz.getName(),VUmsCrosstbl_.apr.getName(),VUmsCrosstbl_.mai.getName(),VUmsCrosstbl_.jun.getName(),VUmsCrosstbl_.jul.getName(),VUmsCrosstbl_.aug.getName(),VUmsCrosstbl_.sep.getName(),VUmsCrosstbl_.okt.getName(),VUmsCrosstbl_.nov.getName(),VUmsCrosstbl_.dez.getName(),VUmsCrosstbl_.sum.getName());
            this.tblUmsCross.setColumnHeaders(new String[] {"rid", "l1_Id", "l1_GroupName", "l2_Id", "l2_GroupName", "Jan","Feb","Mrz","Apr","Mai","Jun","Jul","Aug","Sep","Okt","Nov","Dez", "Sum"});


        }

此后,数据在表中可见。
我很高兴能解决这个问题。
rgds
OpaHeinz