如何在列表框中显示值,其中该值来自 ZK 上的 createNativeQuery 结果?
当我必须在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是将 UI 组件与集合关联时的典型场景。您可以参考 这里了解更多详细信息,但基本思想是使用点访问实体属性。数据绑定表达式中的运算符(注意:您必须在实体类中为这些属性定义 getter 方法)。因此,在您的情况下,您的列表项声明应该类似于这样
希望这会有所帮助。
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
Hope this helps.
好吧,正如我所保证的,我唯一要做的就是实现 ListitemRenderer,并将这样的代码添加到方法渲染中:
索引基于您的本机查询中的列..
并且在 .zul 页面中您只需执行以下操作:
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:
the index is based on your column in your nativequery..
and in .zul page you only have to do this:
itemRenderer
tag add default valueitemRenderer
and themodel
is list based on your controller..thanks for all of your response and sorry for my bad english..thanks..