Class Options
- java.lang.Object
-
- com.googlecode.wicket.jquery.core.Options
-
- All Implemented Interfaces:
Serializable,IClusterable
public class Options extends Object implements IClusterable
Provides a wrapper on aMapthat will contains jQuery behavior options (key/value).
thetoString()methods returns the JSON representation of the options.- Author:
- Sebastien Briquet - sebfz1
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description Options()Constructor.Options(Options options)Constructor which shadow copies an existingOptionsOptions(String key, Object value)Constructor which adds an options defined by a key/value pair.Options(String key, Object... values)Constructor which adds an array of objects, ie: "key" : ["value1", "value2"].Options(String key, List<?> values)Constructor which a list of objects, ie: "key" : ["value1", "value2"].
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static StringasDate(long date)Converts a date to its ISO8601/javascript representation. ie: "2009-11-05T13:15:30+0200" (with the double quotes)static StringasDate(Date date)Converts a date to its ISO8601/javascript representation. ie: "2009-11-05T13:15:30+0200" (with the double quotes)static StringasString(Object value)Converts an object to its javascript representation. ie: "myvalue" (with the double quotes)
If the supplied value is null, "null" is returnedstatic StringasString(String value)Converts a string to its javascript representation. ie: "myvalue" (with the double quotes)static StringasString(List<?> values)Converts a list of objects to its javascript representation. ie: [ "myvalue1", "myvalue2" ] (with the double quotes)Set<Map.Entry<String,Object>>entries()Gets a read-only entry set of optionsstatic StringfromArray(Object... objects)Converts a list of options to a comma delimited string.<T> Tget(String key)Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.Optionsset(String key, Object value)Adds or replace an option defined by a key/value pair.
If for a given key, the value is null, then the pair is removed.Optionsset(String key, Object... values)Optionsset(String key, List<?> values)StringtoString()Gets the JSON representation of the Options
-
-
-
Field Detail
-
QUOTE
public static final String QUOTE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Options
public Options()
Constructor.
-
Options
public Options(Options options)
Constructor which shadow copies an existingOptions- Parameters:
options- the base Options
-
Options
public Options(String key, Object value)
Constructor which adds an options defined by a key/value pair.- Parameters:
key- the option namevalue- the option value
-
Options
public Options(String key, Object... values)
Constructor which adds an array of objects, ie: "key" : ["value1", "value2"].- Parameters:
key- the option namevalues- the option values
-
-
Method Detail
-
asString
public static String asString(Object value)
Converts an object to its javascript representation. ie: "myvalue" (with the double quotes)
If the supplied value is null, "null" is returned- Parameters:
value- the object- Returns:
- the JSON value
-
asString
public static String asString(String value)
Converts a string to its javascript representation. ie: "myvalue" (with the double quotes)- Parameters:
value- the object- Returns:
- the JSON value
-
asString
public static String asString(List<?> values)
Converts a list of objects to its javascript representation. ie: [ "myvalue1", "myvalue2" ] (with the double quotes)- Parameters:
values- theListof values- Returns:
- the JSON value
-
asDate
public static String asDate(long date)
Converts a date to its ISO8601/javascript representation. ie: "2009-11-05T13:15:30+0200" (with the double quotes)- Parameters:
date- the date to convert- Returns:
- the JSON value
-
asDate
public static String asDate(Date date)
Converts a date to its ISO8601/javascript representation. ie: "2009-11-05T13:15:30+0200" (with the double quotes)- Parameters:
date- the date to convert- Returns:
- the JSON value
-
fromArray
public static String fromArray(Object... objects)
Converts a list of options to a comma delimited string.- Parameters:
objects- options- Returns:
- a comma delimited string
-
get
public <T> T get(String key)
Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.- Type Parameters:
T- the object type- Parameters:
key- the key whose associated value is to be returned- Returns:
- the value to which the specified key is mapped, or null if this map contains no mapping for the key
-
set
public final Options set(String key, Object value)
Adds or replace an option defined by a key/value pair.
If for a given key, the value is null, then the pair is removed.- Parameters:
key- - key with which the specified value is to be associatedvalue- - value to be associated with the specified key- Returns:
- this, for chaining
-
set
public final Options set(String key, Object... values)
In addition toset(String, Object)this enables to build trees of Options.
Example:Options o = new Options(); o.set("foo", new Options("foo1", "value1"), new Options("foo2", Options.asString("value2"))); results in json: { "foo": [ { "foo1": value1 }, { "foo2": "value2" } ] }- Parameters:
key- - key with which the specified value is to be associatedvalues- - values to be associated with the specified key- Returns:
- this, for chaining
-
set
public final Options set(String key, List<?> values)
In addition toset(String, Object)this enables to build trees of Options.
Example:Options o = new Options(); o.set("foo", new Options("foo1", "value1"), new Options("foo2", Options.asString("value2"))); results in json: { "foo": [ { "foo1": value1 }, { "foo2": "value2" } ] }- Parameters:
key- - key with which the specified value is to be associatedvalues- - values to be associated with the specified key- Returns:
- this, for chaining
-
entries
public Set<Map.Entry<String,Object>> entries()
Gets a read-only entry set of options- Returns:
- an unmodifiable set of internal map entries
-
-