p:selectOneMenu 中的重复值 [英] Duplicate values in p:selectOneMenu

查看:60
本文介绍了p:selectOneMenu 中的重复值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我有一个 Primefaces selectOneMenu 来直接从数据库显示值.然而,由于它在数据库中多次重复,这些值被多次重复.对于数据库中的每个实例一次.有没有办法检索这些值并只显示其中一个?

Currently I have a Primefaces selectOneMenu to display values direct from the database. However due to it being repeated multiple times in the database, these values are being duplicated multiple times. Once for each instance in the database. Is there any way to retrieve these values and only display one of each?

我在下面提供了 selectOneMenu 的代码,如果需要更多代码,我会添加它.

I have provided the code for the selectOneMenu below, if any more is required I will add it.

            <p:selectOneMenu value="#{addOrderBean.state}" id="state">
                <f:selectItem itemLabel="Select One" itemValue=" "/>
                <f:selectItems value="#{ordersBean.orders}" var="order" itemLabel="#{order.state}" itemValue="#{order.state}"/>
            </p:selectOneMenu>

这里有一张图片来显示我的意思,以防我没有很好地解释它:

Here is an image to display what I mean in case I havent explained it very well:

推荐答案

创建一个 SQL 查询,用于状态表上的不同状态,并在 ordersBean.orders 上调用结果代码>方法.

Create a SQL query, for distinct states on your state table, and call the result on ordersBean.orders method.

类似于:

SELECT DISTINCT 'STATE TABLE'.state FROM 'STATE TABLE';

这篇关于p:selectOneMenu 中的重复值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆