在liferay搜索容器中显示自定义查询(已加入表)的数据

时间:2013-05-22 04:37:04

标签: mysql liferay liferay-6

我已关注this wiki并已成功构建自定义查询。

工作正常。我使用了表之间的连接。

我的问题是如何使用liferay搜索容器在jsp上显示它,因为搜索容器中的className需要一个模型类。

修改
我到现在为止尝试的是:

<%

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个名字中的每一个 我希望名称出现在每个新行上。我如何修改上述代码?

编辑2
考虑到先前定义的name数组,我做了以下内容:

<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每行。

1 个答案:

答案 0 :(得分:3)

我发现nametitlestatusremarks字段都是String(根据您的comment)所以你应该将for转换为Object的{​​{1}}循环,并且您不需要四个String

以下是行标记的外观:

ArrayList

你去,这应该有用。

我认为更清洁的方法是定义一个POJO来存储这些值,然后返回POJO的列表。我没有尝试过第二种方法。

另一种标准方法是在实体<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> 的任何一个中包含额外字段,然后返回该实体的列表,在您的情况下,我假设您有*ImplStudent实体,因此您可以放置​​字段Attendance&amp; status中的remarks然后返回StudentImpl或将List<Student>放入fname并从finder方法返回AttendanceImpl。 (在this comment之后更新)

相关问题