T - type of choice objectpublic abstract class ChoiceProvider<T> extends Object implements org.apache.wicket.model.IDetachable
Acts as a bridge between Select2 components and the application's domain model.
The two important services provided by implementations are:
For the most common usecase where each choice is rendered as a text string see
TextChoiceProvider.
| Constructor and Description |
|---|
ChoiceProvider() |
| Modifier and Type | Method and Description |
|---|---|
void |
detach() |
abstract String |
getDisplayValue(T object)
Get the value for displaying to an end user.
|
abstract String |
getIdValue(T object)
This method is called to get the id value of an object (used as the value attribute of a
choice element) The id can be extracted from the object like a primary key, or if the list is
stable you could just return a toString of the index.
|
abstract void |
query(String term,
int page,
Response<T> response)
Queries application for choices that match the search
term and adds them to the
response |
abstract Collection<T> |
toChoices(Collection<String> ids)
Converts a list of choice ids back into application's choice objects.
|
protected void |
toJson(T choice,
org.apache.wicket.ajax.json.JSONWriter writer)
Converts the specified choice to Json.
|
public abstract String getDisplayValue(T object)
object - the actual objectpublic abstract String getIdValue(T object)
Note that the given index can be -1 if the object in question is not contained in the
available choices.
object - The object for which the id should be generatedindex - The index of the object in the choices list.public abstract void query(String term, int page, Response<T> response)
term and adds them to the
responseterm - search termpage - requested search term results pageresponse - aggregate for matching choices as well as other response optionsprotected void toJson(T choice, org.apache.wicket.ajax.json.JSONWriter writer) throws org.apache.wicket.ajax.json.JSONException
At the very least each choice should contain an id attribute. If no custom rendering
function is specified, the text attribute should also be provided
Example: If mapping a User {Long id, String name} using default rendering the code should look like this:
toJson(User choice, JSONWriter writer)
{
writer.key("id").value(choice.getId()).key("text").value(choice.getName());
}
choice - choice to convertwriter - Json writer that should be used to covnert the choiceorg.apache.wicket.ajax.json.JSONExceptionpublic abstract Collection<T> toChoices(Collection<String> ids)
ids collection will contain
exactly one id, and a collection containing exactly one choice should be returned.ids - collection containing choice idspublic void detach()
detach in interface org.apache.wicket.model.IDetachableCopyright © 2017. All rights reserved.