Skip to content

Commit

Permalink
LPS-134657 Reset param values when searching for the first time
Browse files Browse the repository at this point in the history
  • Loading branch information
adolfopa committed Jul 13, 2021
1 parent 22d49de commit 23415b6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
Expand Up @@ -155,7 +155,7 @@ public SearchContainer<BlogsEntry> getSearchContainer()
"no-entries-were-found");

String orderByCol = ParamUtil.getString(
_httpServletRequest, "orderByCol", "title");
_httpServletRequest, "orderByCol", _getDefaultOrderByCol());

entriesSearchContainer.setOrderByCol(orderByCol);

Expand All @@ -177,6 +177,17 @@ public SearchContainer<BlogsEntry> getSearchContainer()
return entriesSearchContainer;
}

private String _getDefaultOrderByCol() {
String mvcRenderCommandName = ParamUtil.getString(
_httpServletRequest, "mvcRenderCommandName");

if (mvcRenderCommandName.equals("/blogs/search")) {
return "relevance";
}

return "title";
}

private void _populateResults(SearchContainer<BlogsEntry> searchContainer)
throws PortalException {

Expand Down
Expand Up @@ -185,13 +185,33 @@ public String getSearchActionURL() {
return PortletURLBuilder.createRenderURL(
liferayPortletResponse
).setMVCRenderCommandName(
"/blogs/view"
"/blogs/search"
).setNavigation(
navigation
).setParameter(
"orderByCol", getOrderByCol()
"orderByCol",
() -> {
String mvcRenderCommandName = ParamUtil.getString(
httpServletRequest, "mvcRenderCommandName");

if (mvcRenderCommandName.equals("/blogs/search")) {
return getOrderByCol();
}

return null;
}
).setParameter(
"orderByType", getOrderByType()
"orderByType",
() -> {
String mvcRenderCommandName = ParamUtil.getString(
httpServletRequest, "mvcRenderCommandName");

if (mvcRenderCommandName.equals("/blogs/search")) {
return getOrderByType();
}

return null;
}
).buildString();
}

Expand Down
Expand Up @@ -40,7 +40,8 @@
property = {
"javax.portlet.name=" + BlogsPortletKeys.BLOGS,
"javax.portlet.name=" + BlogsPortletKeys.BLOGS_ADMIN,
"mvc.command.name=/", "mvc.command.name=/blogs/view"
"mvc.command.name=/", "mvc.command.name=/blogs/search",
"mvc.command.name=/blogs/view"
},
service = MVCRenderCommand.class
)
Expand Down

0 comments on commit 23415b6

Please sign in to comment.