JAVA Apache Wicket AutoComplete Setup

The ShieldUI AutoComplete Apache Wicket component offers streamlined setup and deployment of our libraries.

Since it is a wrapper of our javascript AutoComplete component, you need to include the references to the CSS and JavaScript resources in the HEAD section of your webpage:

<!DOCTYPE html>
<html>
<head>
<title>Shield AutoComplete</title>
<meta charset="utf-8" />

<link rel="stylesheet" type="text/css" href="css/light/all.min.css" />
<script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="js/shieldui-all.min.js"></script>

</head>
<body>
    <input type="text" wicket:id="autocomplete" />
</body>
</html>

Then init the autocomplete and add it to your wicket page like in the following example:

AutoComplete autocomplete = new AutoComplete("autocomplete");
AutoCompleteOptions options = autocomplete.getOptions();

options.setMinLength(2);
options.setTextTemplate("[{code}] {name}");
options.setValueTemplate("{code}");
options.setDataSource(new DataSourceOptions()
                    .setData(
                        new HashMap() {{
                            put("code", "AR");
                            put("name", "Argentina");
                        }},
                        new HashMap() {{
                            put("code", "US");
                            put("name", "United States");
                        }},
                        new HashMap() {{
                            put("code", "GB");
                            put("name", "England");
                        }},
                        new HashMap() {{
                            put("code", "CA");
                            put("name", "Canada");
                        }}
                    )
                    .setSort(new DataSourceOptions.SortOption().setPath("code"))
                    .setFilter(new DataSourceOptions.FilterGroup()
                        .setCondition(DataSourceOptions.Condition.AND)
                        .addFilter(new DataSourceOptions.FilterOption().setPath("name").setFilter(DataSourceOptions.Filter.CONTAINS).setValue("")
                    )
                ));

add(autocomplete);

To see more information on this wrapper, please refer to the following startup guide.