SearchResultAction

The search panel includes an “Actions” section for invoking operations on search results. The available actions that appear in the list can vary, depending on the content type filter setting.

../../../_images/actions1.png

Brightspot provides default action implementations as reflected in the above screenshot. You can also create custom actions by implementing the SearchResultAction interface and a page servlet that operates on search results. Brightspot automatically detects new action implementations.

To implement SearchResultAction, override the following methods:

  • getGroup sets a group name in the UI for a set of related action implementations, like “Bulk”.
  • getPosition sets the top-down position of the action in the UI list of actions. Implementations with the same position settings are arranged in alphabetical order based on the class name.
  • shouldDisplay shows or hides the action in the UI
  • writeHtml constructs the HTML link that invokes the action when the button is clicked in the UI. The link references the path of the page servlet that processes the search results.

The following code example shows the writeHtml implementation for the SaveSearchResultAction, which saves the search for the current result set. The method takes ToolPageContext, Search, and SearchResultSelection objects. The ToolPageContext object constructs the HTML link to the action servlet.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
@Override
 public void writeHtml(
         ToolPageContext page,
         Search search,
         SearchResultSelection selection)
         throws IOException {

   page.writeStart("div", "class", "searchResult-action-simple");
       page.writeStart("a",
               "class", "button",
               "target", "toolUserSaveSearch",
               "href", page.cmsUrl("/toolUserSaveSearch",
                       "search", page.url("", Search.NAME_PARAMETER, null)));
           page.writeHtml(page.localize(SaveSearchResultAction.class, "action.saveSearch"));
       page.writeEnd();
   page.writeEnd();
 }

In the previous snippet—

  • Lines 12–13 construct the URL to the page servlet, specified in the servlet routing path as toolUserSaveSearch.
  • Line 14 specifies the label on the action button. If Brightspot is localized, you can pass a resource key to retrieve the label for the applicable browser language. For the search result APIs in the Brightspot project, place resource files in <project>src/main/resources/com/psddev/cms/tool/search.