context.getRequest().setAttribute("Countries",
PersistenceManager.getInstance().getUserPersistence().getAllCountries());
context.getRequest().setAttribute("Roles",
PersistenceManager.getInstance().getAuthorizationPersistence().getAllRoles());
UserSearchForm userForm = (UserSearchForm) form;
if (this.empty(userForm.getCountryId()) && this.empty(userForm.getEmail()) &&
this.empty(userForm.getFirstName()) && this.empty(userForm.getHandle()) &&
this.empty(userForm.getLastName()) && this.empty(userForm.getRoleId()) && this.empty(userForm.getSchool())) {
return this.handleSuccess(mapping, context, "success");
}
UserCriteria criteria = userForm.toUserCriteria();
String export = context.getRequest().getParameter("exportFormat");
if ("txt".equalsIgnoreCase(export)) {
List<UserProfile> users =
PersistenceManager.getInstance().getUserPersistence().searchUserProfiles(criteria, 0,
Integer.MAX_VALUE);
return this.export(context, criteria, users, export);
} else if ("xls".equalsIgnoreCase(export)) {
List<UserProfile> users =
PersistenceManager.getInstance().getUserPersistence().searchUserProfiles(criteria, 0,
Integer.MAX_VALUE);
return this.export(context, criteria, users, export);
}
long paging = Utility.parseLong(userForm.getPaging(), 10, 50);;
long usersNumber = PersistenceManager.getInstance().getUserPersistence().searchUserProfilesCount(criteria);
if (usersNumber == 0) {
context.setAttribute("users", new ArrayList<UserProfile>());
context.setAttribute("pageNumber", new Long(0));
context.setAttribute("totalPages", new Long(0));
context.setAttribute("paging", new Long(paging));
context.setAttribute("total", new Long(0));
return this.handleSuccess(mapping, context, "success");
}
long totalPages = (usersNumber - 1) / paging + 1;
long pageNumber = Utility.parseLong(userForm.getPageNumber(), 1, totalPages);
long startIndex = paging * (pageNumber - 1);
List<UserProfile> users =
PersistenceManager.getInstance().getUserPersistence().searchUserProfiles(criteria, (int) startIndex,
(int) paging);