在liferay搜索容器中显示来自自定义查询(连接表)的数据

See*_*a K 5 mysql liferay liferay-6

我已关注此 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>  
Run Code Online (Sandbox Code Playgroud)

我上面所做的操作在一列中显示 10 个名称中的每个名称 10 次。
我希望名称出现在每个新行上。我应该如何修改上面的代码?

编辑2
考虑到name之前的数组定义,我执行了以下操作:

<liferay-ui:search-container-column-text name="employee name" href = "">

    <%=name.getClass().getDeclaredFields().toString() %>

</liferay-ui:search-container-column-text>
Run Code Online (Sandbox Code Playgroud)

通过上面的内容,我得到的结果类似于:[Ljava.lang.reflect.Field;@195f1af在每一行。

Pra*_*h K 4

我看到name、title和字段都是(根据您的评论status) ,因此在循环中您应该将 转换为 a并且不需要四个字段。remarksStringforObjectStringArrayList

行标签如下所示:

<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>
Run Code Online (Sandbox Code Playgroud)

就这样,这应该可行。

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

另一种标准方法是在任何一个实体中包含额外的字段*Impl,然后返回该实体的列表,在您的情况下,我假设您有Student和Attendance实体,因此您可以将字段status&remarks放入StudentImpl,然后返回 aList<Student>或fname放入AttendanceImplandList<Attendance>从 finder 方法返回。(此评论后更新)