Display data from user query (inserted tables) in liferay search container

I followed this wiki and successfully created a custom query.

It works great. I used a join between tables.

My question is how to display it on jsp using the liferay search container, since className in the search container requires one model class.

EDIT:
I still tried 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> 

What I did above displays each of 10 names 10 times in a column.
I want the names to appear on every new line. How do I change the code above?

EDIT 2
Given that 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> 

With the above, I get the result: [Ljava.lang.reflect.Field;@195f1af for each line.

+4
source share
1 answer

I see that the fields name , title , status and remarks all String (according to your comment ) so in the for loop you should use Object as String , and for this you do not need four ArrayList .

Here's what the line tag looks like:

 <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> 

There you go, it should work.

A cleaner way, in my opinion, is to define a POJO that will store these values, and then you can return the POJO list. However, I have not tried the second approach.

Another standard approach is to include additional fields in any of the *Impl objects, and then return a list of this object, in your case, I assume that you have Student and Attendance objects, so you can status and remarks fields in StudentImpl , and then return List<Student> or put fname in AttendanceImpl and return List<Attendance> from the search method. (updated after this comment )

+3
source

Source: https://habr.com/ru/post/1482081/


All Articles