我有一个Hibernate查询,它向我返回列表,我想在Primeface的用户界面上显示列表中的不同元素。如何实现呢?提前致谢!

这是我的方法:

public List<Object> showMessages(TRequest requestVar, Long agencyId) {
        if (!em.getTransaction().isActive())
            em.getTransaction().begin();
        Query queryMessages = em
                .createQuery("select user.name, msg.messageBody, msg.dateSent "
                        + "from TUser user join user.sentMessages msg "
                        + "where user.id in (:userId, :agencyId) "
                        + "and msg.messageGroup = :messageGroup "
                        + "order by msg.dateSent asc");

        queryMessages.setParameter("userId",
                Long.valueOf(requestVar.getAuthor().getId()));
        queryMessages.setParameter("agencyId", agencyId);
        queryMessages.setParameter("messageGroup", messageGroup);

        List<Object> messages = queryMessages.getResultList();
        return messages;
    }

最佳答案

我找到了解决方案:

<c:forEach
                            items="#{userRequestBean.showMessages(userRequestBean.request, agency[1])}"
                            var="message">

                            <h:outputText value="#{message[1]}"
                                style="width: 100px; white-space: normal; border: 3px" />
                    </c:forEach>

10-07 17:10