如何在列表框中显示值,其中该值来自 ZK 上的 createNativeQuery 结果?

发布于 2024-11-16 12:30:59 字数 3611 浏览 3 评论 0原文

当我必须在 Hibernate 中显示 createNativeQuery 结果的值时,我遇到了非常令人沮丧的问题,我的代码是这样的:

public List<Rmerchant> getListMerchantbyMasterMerchanttest(){
        List<Rmerchant> lstMerchant=em.createNativeQuery("select merchant_name,merchant_email,merchant_status from rmerchant where master_merchant_id=123")

                .getResultList();
        return lstMerchant;
    }

这是简单的查询,因为事先我必须创建更复杂的查询,例如使用 count,以及查询中的许多函数,我在 ZK zul 页面中的代码如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" arg0="./test"?>
<?init class="com.nsia.doku.escrow.controller.testController"?>
<zk xmlns="http://www.zkoss.org/2005/zul">
    <window id="test" xmlns:n="native" title="test" border="normal" position="center" apply="com.nsia.doku.escrow.controller.testController">
        <listbox  model="@{test$composer.lstMerchant}"
                vflex="true">
                <auxhead>
                    <auxheader colspan="3" class="topic">EDS Status</auxheader>
                </auxhead>
                <listhead>
                    <listheader label="Merchant Name"  align="center"/>
                    <listheader label="merchant email" align="center" />
                    <listheader label="merchant status"  align="center" />

                </listhead>
                <listitem self="@{each=lstMerchant}">
                    <listcell label='@[lstMerchant}' />
                    <listcell label='@{lstMerchant}' />
                    <listcell label='@{lstMerchant}' />
                </listitem>
            </listbox>

    </window>

</zk>

如果值像我写的那样,则列表单元将如下所示:

merchant name                                  merchant email                                
[merch001, jhjhjh, null]                       [merch001, jhjhjh, null]                      
[fahmi0090908789788, [email protected], null]    [fahmi0090908789788, [email protected], null] 

如果我在列表项中更改代码如下:

<listitem self="@{each=lstMerchant}">
                    <listcell label='@[lstMerchant[0]}' />
                    <listcell label='@{lstMerchant[1]}' />
                    <listcell label='@{lstMerchant[2]}' />
                </listitem>

                or 
<listitem self="@{each=lstMerchant}">
                    <listcell label='@[lstMerchant["0"]}' />
                    <listcell label='@{lstMerchant["1"]}' />
                    <listcell label='@{lstMerchant["2"]}' />
                </listitem>

                or 
                <listitem self="@{each=lstMerchant}">
                    <listcell label='@[lstMerchant["merchant_name"]}' />
                    <listcell label='@{lstMerchant["merchant_email"]}' />
                    <listcell label='@{lstMerchant["merchant_status"]}' />
                </listitem>

                or

                every lstMerchant i change with each

不起作用,又名列表项显示到行但值为空,,我对这个问题很困惑,也许有人可以帮助我?

我曾经使用icefaces创建网络,如果在icefaces中,我只需将此标签放在单元格中:

currentRow[0] 但在Zk中,我还没有找到它..

我为我的英语不好而感到抱歉这个新手问题..谢谢..:D

iam getting very frustating problem when i have to show the value from result of createNativeQuery in Hibernate,my code is like this:

public List<Rmerchant> getListMerchantbyMasterMerchanttest(){
        List<Rmerchant> lstMerchant=em.createNativeQuery("select merchant_name,merchant_email,merchant_status from rmerchant where master_merchant_id=123")

                .getResultList();
        return lstMerchant;
    }

this is the simpe query because in advance i have to create more complex query like using count,and many function in query,and my code in ZK zul page like this:

<?xml version="1.0" encoding="UTF-8"?>
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" arg0="./test"?>
<?init class="com.nsia.doku.escrow.controller.testController"?>
<zk xmlns="http://www.zkoss.org/2005/zul">
    <window id="test" xmlns:n="native" title="test" border="normal" position="center" apply="com.nsia.doku.escrow.controller.testController">
        <listbox  model="@{test$composer.lstMerchant}"
                vflex="true">
                <auxhead>
                    <auxheader colspan="3" class="topic">EDS Status</auxheader>
                </auxhead>
                <listhead>
                    <listheader label="Merchant Name"  align="center"/>
                    <listheader label="merchant email" align="center" />
                    <listheader label="merchant status"  align="center" />

                </listhead>
                <listitem self="@{each=lstMerchant}">
                    <listcell label='@[lstMerchant}' />
                    <listcell label='@{lstMerchant}' />
                    <listcell label='@{lstMerchant}' />
                </listitem>
            </listbox>

    </window>

</zk>

if the value is like what i write,the listcell will be like this:

merchant name                                  merchant email                                
[merch001, jhjhjh, null]                       [merch001, jhjhjh, null]                      
[fahmi0090908789788, [email protected], null]    [fahmi0090908789788, [email protected], null] 

if the code i change in listitem like this:

<listitem self="@{each=lstMerchant}">
                    <listcell label='@[lstMerchant[0]}' />
                    <listcell label='@{lstMerchant[1]}' />
                    <listcell label='@{lstMerchant[2]}' />
                </listitem>

                or 
<listitem self="@{each=lstMerchant}">
                    <listcell label='@[lstMerchant["0"]}' />
                    <listcell label='@{lstMerchant["1"]}' />
                    <listcell label='@{lstMerchant["2"]}' />
                </listitem>

                or 
                <listitem self="@{each=lstMerchant}">
                    <listcell label='@[lstMerchant["merchant_name"]}' />
                    <listcell label='@{lstMerchant["merchant_email"]}' />
                    <listcell label='@{lstMerchant["merchant_status"]}' />
                </listitem>

                or

                every lstMerchant i change with each

is not working,aka the listitem show to row but the value is null,,iam so confuse about this problem,maybe somebody can help me?

i used to create web using icefaces,if in icefaces,i just have to place this tag in cell:

currentRow[0] but in Zk,i havent found it..

im sorry for my bad english and this newbie question..thanks..:D

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

半世蒼涼 2024-11-23 12:30:59

这是将 UI 组件与集合关联时的典型场景。您可以参考 这里了解更多详细信息,但基本思想是使用点访问实体属性。数据绑定表达式中的运算符(注意:您必须在实体类中为这些属性定义 getter 方法)。因此,在您的情况下,您的列表项声明应该类似于这样

<listitem self="@{each=merchant}">
                <listcell label='@{merchant.name}' />
                <listcell label='@{merchant.email}' />
                <listcell label='@{merchant.address}' />
            </listitem>

希望这会有所帮助。

This is a typical scenario while associating UI components with a collection. You can refer here for more details but basic idea is to access entity properties using dot . operator within your data-binding expression (Note: you have to have getter methods defined for these properties in your entity class). So in your case your listitem declaration should look something like this

<listitem self="@{each=merchant}">
                <listcell label='@{merchant.name}' />
                <listcell label='@{merchant.email}' />
                <listcell label='@{merchant.address}' />
            </listitem>

Hope this helps.

东京女 2024-11-23 12:30:59

好吧,正如我所保证的,我唯一要做的就是实现 ListitemRenderer,并将这样的代码添加到方法渲染中:

public void render(Listitem li, Object data) throws Exception {
        Object[] obj=(Object[]) data;
        new Listcell((String) obj[16]).setParent(li);
        new Listcell((String) obj[17]).setParent(li);
        new Listcell((String) obj[22]).setParent(li);
        new Listcell((String) obj[0]).setParent(li);
        new Listcell((String) obj[1]).setParent(li);
        new Listcell((String) obj[2]).setParent(li);
        new Listcell((String) obj[3]).setParent(li);
        new Listcell((String) obj[18]).setParent(li);
        new Listcell((String) obj[19]).setParent(li);
        new Listcell((String) obj[20]).setParent(li);
        new Listcell((String) obj[21]).setParent(li);
        new Listcell((String) obj[4]).setParent(li);
        new Listcell((String) obj[5]).setParent(li);
        new Listcell((String) obj[6]).setParent(li);
        new Listcell((String) obj[7]).setParent(li);
        new Listcell((String) obj[8]).setParent(li);
        new Listcell((String) obj[10]).setParent(li);
        new Listcell((String) obj[15]).setParent(li);
        new Listcell((String) obj[12]).setParent(li);
        new Listcell((String) obj[13]).setParent(li);
        new Listcell((String) obj[14]).setParent(li);
        new Listcell((String) obj[23]).setParent(li);
        new Listcell((String) obj[24]).setParent(li);
        new Listcell((String) obj[25]).setParent(li);


    }

索引基于您的本机查询中的列..

并且在 .zul 页面中您只需执行以下操作:

<listbox  model="@{dokureport$composer.lstTrans}"
                vflex="true" itemRenderer="@{dokureport$composer.itemRenderer}">

itemRenderer 标记添加默认值 itemRenderer ,并且 model 是基于您的控制器的列表。感谢您的所有回复,并对我的错误表示歉意英语..谢谢..

ok as i promise,the thing only i have to do is implements ListitemRenderer,and add the code like this to method render:

public void render(Listitem li, Object data) throws Exception {
        Object[] obj=(Object[]) data;
        new Listcell((String) obj[16]).setParent(li);
        new Listcell((String) obj[17]).setParent(li);
        new Listcell((String) obj[22]).setParent(li);
        new Listcell((String) obj[0]).setParent(li);
        new Listcell((String) obj[1]).setParent(li);
        new Listcell((String) obj[2]).setParent(li);
        new Listcell((String) obj[3]).setParent(li);
        new Listcell((String) obj[18]).setParent(li);
        new Listcell((String) obj[19]).setParent(li);
        new Listcell((String) obj[20]).setParent(li);
        new Listcell((String) obj[21]).setParent(li);
        new Listcell((String) obj[4]).setParent(li);
        new Listcell((String) obj[5]).setParent(li);
        new Listcell((String) obj[6]).setParent(li);
        new Listcell((String) obj[7]).setParent(li);
        new Listcell((String) obj[8]).setParent(li);
        new Listcell((String) obj[10]).setParent(li);
        new Listcell((String) obj[15]).setParent(li);
        new Listcell((String) obj[12]).setParent(li);
        new Listcell((String) obj[13]).setParent(li);
        new Listcell((String) obj[14]).setParent(li);
        new Listcell((String) obj[23]).setParent(li);
        new Listcell((String) obj[24]).setParent(li);
        new Listcell((String) obj[25]).setParent(li);


    }

the index is based on your column in your nativequery..

and in .zul page you only have to do this:

<listbox  model="@{dokureport$composer.lstTrans}"
                vflex="true" itemRenderer="@{dokureport$composer.itemRenderer}">

itemRenderer tag add default value itemRenderer and the model is list based on your controller..thanks for all of your response and sorry for my bad english..thanks..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文