在Liferay搜索容器中显示来自自定义查询(联接表)的数据 [英] Display data from Custom Query(Joined tables) in liferay search container
问题描述
I have followed this wiki and have successfully built a custom query.
工作正常.我在表之间使用了联接.
It works fine. I have used a join between tables.
我的问题是我如何使用liferay搜索容器在jsp上显示它,因为搜索容器中的className需要一个模型类.
My question is how do I display it on a jsp using liferay search container since className in search container requires one model class.
我到目前为止尝试过的是:
What I have tried till now is this:
<%
getAttendanceData attName = new getAttendanceData();
List<Object[]> displayAttListName = AttendanceLocalServiceUtil.findAttendance();
ArrayList name = new ArrayList();
ArrayList title = new ArrayList();
ArrayList status = new ArrayList();
ArrayList remarks = new ArrayList();
for(Object[] att:displayAttListName) {
name.add(att[0]);
title.add(att[1]);
status.add(att[2]);
remarks.add(att[3]);
}
%>
<liferay-ui:search-container delta="20" emptyResultsMessage="No Results Found">
<liferay-ui:search-container-results
total="<%= displayAttListName.size() %>"
results="<%= ListUtil.subList(displayAttListName , searchContainer.getStart(), searchContainer.getEnd()) %>"
/>
<liferay-ui:search-container-row modelVar="search"
className="java.lang.Object">
<%
for(Object displayName:name) {
%>
<liferay-ui:search-container-column-text name='studName' value = '<%=String.valueOf(displayName)%>' href="">
</liferay-ui:search-container-column-text>
<%
}
%>
</liferay-ui:search-container-row>
<liferay-ui:search-iterator/>
</liferay-ui:search-container>
我在上面所做的事情在一列中显示了10个名称中的每10个.
我希望名称出现在每个新行上.我应该如何修改上面的代码?
What I have done above displays each of the 10 names 10 times in a column.
I want the names to appear on each new row. How shoould I modify the above code?
编辑2
考虑到name
数组定义较早,我做了以下事情:
EDIT 2
Considering the name
array defines earlier I did the following:
<liferay-ui:search-container-column-text name="employee name" href = "">
<%=name.getClass().getDeclaredFields().toString() %>
</liferay-ui:search-container-column-text>
使用上述方法,我得到的结果类似:每行[Ljava.lang.reflect.Field;@195f1af
.
With the above, I am getting the result something like: [Ljava.lang.reflect.Field;@195f1af
on each row.
推荐答案
我看到name
,title
,status
和remarks
字段都是String
(根据您的
I see that the name
, title
, status
and remarks
field are all String
(as per your comment) so in the for
loop you should cast the Object
as a String
and you don't need the four ArrayList
for this.
以下是行标记的外观:
<liferay-ui:search-container-row className="java.lang.Object" modelVar="search">
<%--
Since an "Object[]" is nothing but an "Object", we first cast the "search"
instance to an "Object[]" and then to a "String"
--%>
<liferay-ui:search-container-column-text name='name' value='<%= (String) ((Object[])search)[0] %>' />
<liferay-ui:search-container-column-text name='title' value='<%= (String) ((Object[])search)[1] %>' />
<liferay-ui:search-container-column-text name='status' value='<%= (String) ((Object[])search)[2] %>' />
<liferay-ui:search-container-column-text name='remarks' value='<%= (String) ((Object[])search)[3] %>' />
</liferay-ui:search-container-row>
你去了,这应该工作.
我认为更干净的方法是定义一个POJO,该POJO将存储这些值,然后可以返回POJO的列表.我还没有尝试第二种方法.
A more cleaner way I think would be to have a POJO defined that would store these values and then the POJO's list can be returned. I have not tried the second approach though.
另一种标准方法是在实体的任何*Impl
中包含额外的字段,然后返回该实体的列表,在您的情况下,我假设您具有Student
和Attendance
实体,因此可以将字段status
& StudentImpl
中的remarks
,然后返回List<Student>
或将fname
放入AttendanceImpl
,然后从finder方法返回List<Attendance>
. (在此评论之后更新)
Another standard approach is to include extra fields in any one of the entity's *Impl
and then returning the list of that entity, in your case I would assume you have Student
and Attendance
entities, so you can put the fields status
& remarks
in StudentImpl
and then return a List<Student>
or put fname
in AttendanceImpl
and return List<Attendance>
from the finder method. (updated after this comment)
这篇关于在Liferay搜索容器中显示来自自定义查询(联接表)的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!