Skip to content

save selected category as cookie #173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 31, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
import java.util.Set;
import java.util.stream.Collectors;

import javax.servlet.http.Cookie;

/**
* This class is the struts action class which is used for listing all projects.
* <p>
Expand Down Expand Up @@ -151,7 +153,20 @@ public String execute() throws BaseException {

request.setAttribute("userProjectTypes", userProjectTypes);

// read cookies to remember user's selected category
String categoryCookie = "";
for(Cookie c : request.getCookies()) {
if (c.getName().equals(scope + "-categoryId")) {
categoryCookie = c.getValue();
break;
}
}

String selectedCategoryParam = request.getParameter("category");
// if a specific category is not requested explicitly, use category value from cookie.
if (selectedCategoryParam == null || selectedCategoryParam.isEmpty()) {
selectedCategoryParam = categoryCookie;
}
Long selectedCategoryId = null;
String categoryName = "";
int totalProjectCount = 0;
Expand Down Expand Up @@ -185,6 +200,8 @@ public String execute() throws BaseException {
return SUCCESS;
}
request.setAttribute("selectedCategoryId", selectedCategoryId);
// set selected category as cookie
response.addCookie(new Cookie(scope + "-categoryId", String.valueOf(selectedCategoryId)));
// pagination parameter
String pageParameter = request.getParameter("page");
Integer currentPage = null;
Expand Down