Skip to content

Commit 93265d3

Browse files
committedMay 17, 2012
initial checkin
0 parents  commit 93265d3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+21714
-0
lines changed
 

‎.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.project
2+
.classpath
3+
target
4+

‎README.md

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
Wicket-Select2
2+
==============
3+
4+
This project provides [Apache Wicket](http://wicket.apache.org) components that leverage [Select2](http://ivaynberg.github.com/select2) JavaScript library to build select boxes that provide Ajax choice filtering, custom rendering, etc.
5+
6+
Installation
7+
------------
8+
9+
<dependency>
10+
<groupId>com.vaynberg.wicket.select2</groupId>
11+
<artifactId>wicket-select2</artifactId>
12+
<version>1.0-SNAPSHOT</version>
13+
</dependency>
14+
15+
Configuration
16+
-------------
17+
18+
Wicket-Select2 provides the `Select2ApplicationSettings` class that can be used to configure application-global settings such as:
19+
20+
* Whether or not internal version of JQuery library will be included any time a Wicket-Select2 components is used
21+
* Whether or not default CSS resource will be included any time a Wicket-Select2 component is used
22+
* And other similar options
23+
24+
These settings allow the application to customize the behavior of Wicket-Select2 components without creating application-specific subclasses for all of them.
25+
26+
Example:
27+
28+
public class MyApplication extends WebApplication {
29+
public void init() {
30+
super.init();
31+
ApplicationSettings.get().setIncludeJquery(false);
32+
}
33+
}
34+
35+
Integration
36+
-----------
37+
38+
The main interface between your application and Wicket-Select2 components is the `ChoiceProvider`:
39+
40+
public abstract class ChoiceProvider<T> implements IDetachable {
41+
/**
42+
* Queries application for choices that match the search {@code term} and adds them to the {@code response}
43+
*/
44+
public abstract void query(String term, int page, Response<T> response);
45+
46+
/**
47+
* Converts the specified choice to Json.
48+
*/
49+
public abstract void toJson(T choice, JSONWriter writer) throws JSONException;
50+
51+
/**
52+
* Converts a list of choice ids back into application's choice objects. When the choice provider is attached to a
53+
*/
54+
public abstract Collection<T> toChoices(Collection<String> ids);
55+
}
56+
57+
Once you implement this interface your application can communicate with the Select2 components. Then its simply a matter of adding any one of the provided components to your page and configuring various Select2 options through the component. For example a single-select component can be added and configured like this:
58+
59+
// add the single-select component
60+
Select2Choice<Country> country = new Select2Choice<Country>(
61+
"country", new PropertyModel(this, "country"), new CountriesProvider());
62+
form.add(country);
63+
64+
// configure various Select2 options
65+
country.getSettings().setMinimumInputLength(1);
66+
67+
The two main Select2 components are the `Select2Choice` which provides single-selection and `Select2MultiChoice` which provides multi-selection.
68+
69+
See the `wicket-select2-examples` submodule for code examples.
70+
71+
License
72+
-------
73+
Copyright 2012 Igor Vaynberg
74+
75+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with the License. You may obtain a copy of the License at:
76+
77+
http://www.apache.org/licenses/LICENSE-2.0
78+
79+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

0 commit comments

Comments
 (0)