So I changed up and went with this person's wiki instead and that one worked much better for me. I ended up using the code below:
1<%
2String viewUsersRedirect = ParamUtil.getString(request, "viewUsersRedirect");
3
4PortletURL portletURL = (PortletURL)request.getAttribute("view.jsp-portletURL");
5
6if (Validator.isNotNull(viewUsersRedirect)) {
7 portletURL.setParameter("viewUsersRedirect", viewUsersRedirect);
8}
9%>
10
11<c:if test="<%= Validator.isNotNull(viewUsersRedirect) %>">
12 <aui:input name="viewUsersRedirect" type="hidden" value="<%= viewUsersRedirect %>" />
13</c:if>
14
15<%
16 PortalPreferences portalPrefs = PortletPreferencesFactoryUtil.getPortalPreferences(request);
17 String sortByCol = ParamUtil.getString(request, "orderByCol");
18 String sortByType = ParamUtil.getString(request, "orderByType");
19
20 if (Validator.isNotNull(sortByCol ) && Validator.isNotNull(sortByType )) {
21
22 portalPrefs.setValue("NAME_SPACE", "sort-by-col", sortByCol);
23 portalPrefs.setValue("NAME_SPACE", "sort-by-type", sortByCol);
24
25 } else {
26
27 sortByCol = portalPrefs.getValue("NAME_SPACE", "sort-by-col", "Last Name");
28 sortByType = portalPrefs.getValue("NAME_SPACE", "sort-by-type ", "asc");
29 }
30%>
31
32<liferay-ui:search-container
33 searchContainer="<%= new UserSearch(renderRequest, portletURL) %>"
34 emptyResultsMessage="No Results Were found for the Selected Criteria"
35>
36 <aui:input disabled="<%= true %>" name="usersRedirect" type="hidden" value="<%= portletURL.toString() %>" />
37
38 <liferay-ui:search-container-results>
39 <%
40 long classNameId = ClassNameLocalServiceUtil.getClassNameId(User.class);
41 long companyId = PortalUtil.getDefaultCompanyId();
42
43 List<ExpandoValue> values = ExpandoValueLocalServiceUtil.getColumnValues(companyId, classNameId, ExpandoTableConstants.DEFAULT_TABLE_NAME, "show-in-directory", "true", -1, -1);
44
45 List<User> users = new ArrayList<User>();
46 User cppUser;
47
48 for (int i = 0; i < values.size(); i++) {
49 long userId = values.get(i).getClassPK();
50 try {
51 cppUser = UserLocalServiceUtil.getUser(userId);
52 users.add(cppUser);
53 } catch(NoSuchUserException e ){
54 ////user with this primary key was not found in DB .....
55 }
56 }
57
58 Collections.sort(users,new Comparator<User>(){
59 public int compare(User u1, User u2) {
60 return u1.getLastName().compareToIgnoreCase(u2.getLastName());
61 }
62 });
63
64 results = ListUtil.subList(users, searchContainer.getStart(), searchContainer.getEnd());
65
66 total = users.size();
67
68 pageContext.setAttribute("results", results);
69 pageContext.setAttribute("total", total);
70 %>
71 </liferay-ui:search-container-results>
72
73 <liferay-ui:search-container-row
74 className="com.liferay.portal.model.User"
75 escapedModel="<%= true %>"
76 keyProperty="userId"
77 modelVar="user2"
78 rowIdProperty="screenName"
79 >
80
81 <liferay-portlet:renderURL varImpl="rowURL">
82 <portlet:param name="struts_action" value="/directory/view_user" />
83 <portlet:param name="tabs1" value="<%= HtmlUtil.escape(tabs1) %>" />
84 <portlet:param name="redirect" value="<%= searchContainer.getIteratorURL().toString() %>" />
85 <portlet:param name="p_u_i_d" value="<%= String.valueOf(user2.getUserId()) %>" />
86 </liferay-portlet:renderURL>
87
88 <%@ include file="/html/portlet/directory/user/search_columns.jspf" %>
89 </liferay-ui:search-container-row>
90
91 <div class="separator"><!-- --></div>
92
93 <liferay-ui:search-iterator />
94
95</liferay-ui:search-container>
I found this by utilizing this wiki post:
Search for an object using custom attributes.
The other trick in this was to re-achieve my sorting. I tried using the Custom Comparators I've seen out there but since I was doing this in a hook, I was unable to get them to work. Has to do, apparently, with the code ending up in a different place than the jsp page with a hook.
This is working and seems to have solved the problems. I'd love any feedback on ways to streamline though.
Thanks!
Please sign in to flag this as inappropriate.