2013-05-22 36 views
4

我跟着this wiki併成功構建了自定義查詢。在Liferay搜索容器中顯示自定義查詢(連接表)的數據

它工作正常。我在表格之間使用了連接。

我的問題是如何使用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次列。
我希望名稱出現在每一個新行上。我應該如何修改上面的代碼?

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

+0

你從'選擇'中得到什麼?通常,在「服務」構建器的「自定義查詢」中,您將獲得一個類/實體的實例數組。表 – yannicuLar

+1

@ yannicuLar: 我從兩個表中獲取數據。我加入了: select studat(stud.studFname,'',stud.studLname)as studName,stud.studTitle,attendance.attRemarks,attendance.attStatus from student stud left outer join attendance on stud.studId =考勤,考勤和考勤。attDate ='2013-05-20'; 我採取了內部連接。 如何在liferay搜索容器中顯示上述查詢的結果? 像我說我不知道​​該怎麼把className –

+0

@ yannicuLar:: 對不起,我已經採取了左外連接..不內連接..就像我在以前的評論中說的 –

回答

3

我看到nametitlestatusremarks場均String(按你comment),所以在for循環,你應該投的ObjectString,你不需要四個ArrayList這一點。

這裏是行標籤會是什麼樣子:

<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的列表。儘管如此,我還沒有嘗試過第二種方法。

另一種標準方法是包括在任何一個額外的字段實體的*Impl,然後再返回該實體的名單,你的情況我會假設你有StudentAttendance實體,所以你可以把領域status & remarksStudentImpl中,然後返回List<Student>或將fname寫入AttendanceImpl,並從查找器方法返回List<Attendance>。 (在this comment後更新)

+0

給出的答案下面的評論我剛剛回答同樣的問題:-D –

+0

@Prakash K: 我只是試了一下,發佈了相同的代碼;)對不起,如果我誤導了。 我應該如何顯示數組的每個元素?我已經告訴過你發生了什麼事。在liferay搜索容器中,我嘗試打印數組名稱,數組中的所有元素都打印在一行中。它發生在每一行。 假設如果我從查詢(使用連接)中獲取10條記錄,則每行有10條記錄顯示10行。我希望每行都有來自數據庫的一個值。當我在表之間進行連接時,如何獲取liferay搜索容器中的記錄?我的方法是否正確? –

+0

@Prakash K: 我被建議使用Maps,hashMaps等。我的基本問題是,如何顯示我從自定義查詢中檢索到的結果集(我已經在表之間應用了左連接)並將結果集顯示在liferay搜索容器中?我很困惑,因爲className需要一個模型類。 –

相關問題