org.wicketstuff.select2
Class ChoiceProvider<T>

java.lang.Object
  extended by org.wicketstuff.select2.ChoiceProvider<T>
Type Parameters:
T - type of choice object
All Implemented Interfaces:
Serializable, org.apache.wicket.model.IDetachable, org.apache.wicket.util.io.IClusterable
Direct Known Subclasses:
TextChoiceProvider

public 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.

Author:
igor
See Also:
Serialized Form

Constructor Summary
ChoiceProvider()
           
 
Method Summary
 void detach()
           
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.
abstract  void toJson(T choice, org.apache.wicket.ajax.json.JSONStringer writer)
          Converts the specified choice to Json.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ChoiceProvider

public ChoiceProvider()
Method Detail

query

public 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

Parameters:
term - search term
page - requested search term results page
response - aggregate for matching choices as well as other response options

toJson

public abstract void toJson(T choice,
                            org.apache.wicket.ajax.json.JSONStringer writer)
                     throws org.apache.wicket.ajax.json.JSONException
Converts the specified choice to Json.

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, JSONStringer writer)
 {
        writer.key("id").value(choice.getId()).key("text").value(choice.getName());
 }
 

Parameters:
choice - choice to convert
writer - Json writer that should be used to covnert the choice
Throws:
org.apache.wicket.ajax.json.JSONException

toChoices

public abstract Collection<T> toChoices(Collection<String> ids)
Converts a list of choice ids back into application's choice objects. When the choice provider is attached to a single-select component the ids collection will contain exactly one id, and a collection containing exactly one choice should be returned.

Parameters:
ids - collection containing choice ids
Returns:
collection containing application choice objects

detach

public void detach()
Specified by:
detach in interface org.apache.wicket.model.IDetachable


Copyright © 2018. All rights reserved.