SearchField Component
The SearchField component presents a text input field with an accompanying button for executing searches. It also provides runtime configuration options accessible via a settings button.
XML Element |
|
|---|---|
Java Class |
|
Attributes |
id - alignSelf - ariaLabel - ariaLabelledBy - autofocus - classNames - colspan - css - enabled - entities - focusShortcut - height - helperText - justifySelf - label - maxHeight - maxWidth - minHeight - minWidth - openMode - placeholder - searchButtonVisible - searchSize - searchStrategy - settingsButtonVisible - tabIndex - themeNames - title - value - valueChangeMode - valueChangeTimeout - visible - width |
Handlers |
AttachEvent - BlurEvent - ComponentValueChangeEvent - DetachEvent - FocusEvent - InputEvent - KeyDownEvent - KeyPressEvent - KeyUpEvent - searchCompletedHandler |
Basics
To add the component on the view, use Jmix Studio.
Click Add Component in the actions panel, then find the SearchField item and double-click it.
The new searchField element will be added both in the Jmix UI structure panel and in the XML descriptor. You can configure standard attributes (id, height, width, etc.) just like any other UI component.
<search:searchField id="searchField"/>
If you don’t use the view designer, declare the search namespace in your view’s XML descriptor manually:
<view xmlns="http://jmix.io/schema/flowui/view"
xmlns:search="http://jmix.io/schema/search/ui"
title="msg://searchView.title">
Runtime Configuration
The searchField includes a settings button (vertical ellipsis ⋮) that opens a configuration dialog, allowing users to dynamically adjust search parameters without modifying the XML.
Users can configure the following options at runtime:
| Configuration | Corresponding Attribute | Description |
|---|---|---|
Search Strategy |
Determines how the search term is processed |
|
Size |
Limits the number of search results |
|
Entities |
Specifies which entities to search (multiple entities can be selected) |
Search Results View
By default, the searchField opens the built-in SearchResultsView. This view handles the search engine querying process and displays results either in the current navigation view or in a dialog, depending on the openMode attribute.
To modify this behavior, configure a SearchCompletedHandler. This can be done either declaratively using the @Install annotation or programmatically using setSearchCompletedHandler().
Example with @Install:
@Autowired
private DialogWindows dialogWindows;
@ViewComponent
private SearchField searchField;
@Install(to = "searchField", subject = "searchCompletedHandler")
private void searchFieldSearchCompletedHandler(
final SearchField.SearchCompletedEvent event) {
DialogWindow<SearchResultsView> searchResultsDialog =
dialogWindows.view(UiComponentUtils.getView(this),
SearchResultsView.class)
.build();
SearchResultsView view = searchResultsDialog.getView();
view.initView(new SearchFieldContext(searchField));
searchResultsDialog.open();
}
Attributes
Common attributes serve the same purpose for all components.
The following attributes are specific to searchField:
| Name | Description | Default |
|---|---|---|
Specifies which entities to search. Multiple entities can be listed as a comma-separated sequence.
|
- |
|
Specifies how the search results view is opened when a search is executed. |
|
|
Shows or hides the search button. |
|
|
Limits the number of search results displayed on single page of search result. |
Inherited from the application property jmix.search.search-result-page-size. |
|
Determines the search strategy applied. See Search Strategies. |
|
|
Shows or hides the settings button ( |
|