在Liferay搜索容器中从不同的数据库表中显示数据:Liferay [英] Display data in Liferay Search Container from different database tables : Liferay

查看:158
本文介绍了在Liferay搜索容器中从不同的数据库表中显示数据:Liferay的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在liferay中使用搜索容器来显示表中的数据。效果很好!!
这里是一段代码:

I have been using search container in liferay to display data from a table. Works well!! here is a snippet of code:

<% 
List<testapp> pendingApprovals = ActionClass.getPendingLeaveApplications();
%>
<liferay-ui:search-container delta="20" emptyResultsMessage="No Results Found">
    <liferay-ui:search-container-results total="<%= pendingApprovals.size() %>"
       results="<%= ListUtil.subList(pendingApprovals , searchContainer.getStart(), searchContainer.getEnd()) %>" />

    <liferay-ui:search-container-row keyProperty = "empId" modelVar="search"
        className="com.test.mis.portal.model.testapp">
        <liferay-ui:search-container-column-text name='Leave Duration' value = '<%=String.valueOf(search.getLeaveDuration())%>'   href="" />
    </liferay-ui:search-container-row>

    <liferay-ui:search-iterator/>
</liferay-ui:search-container>

使用上面的代码我根据一些条件显示testapp表中的数据。
在同一个代码中,我想添加一行并显示数据。此行的数据应来自另一个表。总之,我想使用搜索容器从两个不同的数据库表显示数据。
是否可以做到?我的要求是数据来自两个不同的表

Using the above code I display data from the testapp table based on some condition. In the same code I would like to add a row and display data. The data for this row should come from another table. In short I want to display data using search container from two different database tables. Is it possible to do? My requirement is such that data comes from two different tables

编辑部分请求
我有一个Employee表有一些字段
我有另一个表Leave与一些字段。
empId在映射到Employee表的Leave表中。

EDITED SECTION WITH REQUIREMENT I have Employee table with some fields I have another table Leave with some Fields. empId is in Leave table which maps to Employee table.

我有一个搜索容器whicg只显示Leave表中的数据, b $ b我只想显示Employee表中与Leave表匹配并满足上述条件的字段。

I have a search container whicg displays the data from the Leave table only if the leave is pending I want to display only those fields from Employee table which match with Leave table and satisfy the above condition.

推荐答案

这里的问题有两个面孔:

Your problem here has 2 faces:


  1. 通过使用employeeId外键可以从表Leave和Employee中检索数据。

  2. 在搜索容器中显示无法从一个查询中检索的数据,这是一个非常简单的任务,数据/表。正如你所看到的,名为'className'的'liferay-ui:search-container-row'属性取值为一个类名。关于此,我可以看到2种方法:

a)检索每个离开表,并根据员工ID和待处理状态筛选。然后在每一行中,使用employeeId重新获取Employee实例(通过EmployeeLocalServiceUtil.getEmployee(empId)),然后获取Employye属性,如employee Name等。这将需要在jsp文件上使你的手变脏

a) Retrieve results per Leave table, and filter out by employee ID and pending status. Then in each row, use the employeeId to get back again the Employee instance (by EmployeeLocalServiceUtil. getEmployee(empId)), then get Employye attributes, like employee Name etc. This will need to get your hands dirty on the jsp file

b)创建一个自定义类(如EmployeePendingLeaves),并将其用作searchContainer的模型类。不要将其包含在数据库模型中。只需创建一个扫描Employee和Leave表的函数,并为每个结果行创建一个EmployeePendingLeaves实例。它应该对每一行的

b) Create a custom Class (say EmployeePendingLeaves), and use it as the searchContainer's model class. Don't include it in your database model. Just create a function that scans the Employee and Leave tables, and creates a EmployeePendingLeaves instance for each result row. it should have a variable/attribute for each of the row's columns

这篇关于在Liferay搜索容器中从不同的数据库表中显示数据:Liferay的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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