Package org.primefaces.extensions.util
Class RequestParameterBuilder
java.lang.Object
org.primefaces.extensions.util.RequestParameterBuilder
Builder for request parameters.
- Since:
- 1.1.0
- Author:
- Oleg Varaksin
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a builder instance.RequestParameterBuilder
(boolean useCurrentRequest) Creates a builder instance wihout URL or with the current request URL.Creates a builder instance by the given URL.RequestParameterBuilder
(String url, JsonConverter jsonConverter) Creates a builder instance by the given URL. -
Method Summary
Modifier and TypeMethodDescriptionbuild()
Builds the end result.Encodes given value with a proper encoding.encodeJson
(Object value) Convertes give value to JSON without to know the data type and encodes the converted value with a proper encoding.encodeJson
(Object value, String type) Convertes give value to JSON and encodes the converted value with a proper encoding.Adds a request parameter to the URL.Adds a request parameter to the URL without specifying a data type of the given parameter value.Adds a request parameter to the URL with specifying a data type of the given parameter value.reset()
Resets the internal state in order to be reused.
-
Constructor Details
-
RequestParameterBuilder
public RequestParameterBuilder()Creates a builder instance. This constructor is useful when we only use encode() and encodeJson() methods. -
RequestParameterBuilder
public RequestParameterBuilder(boolean useCurrentRequest) Creates a builder instance wihout URL or with the current request URL.- Parameters:
useCurrentRequest
- boolean flag if the current request URL should be used or not
-
RequestParameterBuilder
Creates a builder instance by the given URL.- Parameters:
url
- URL
-
RequestParameterBuilder
Creates a builder instance by the given URL.- Parameters:
url
- URLjsonConverter
- specific JsonConverter. It should extendsJsonConverter
from PrimeFaces Extensions. If null, the default implementationJsonExposeAwareConverter
is used.
-
-
Method Details
-
paramJson
public RequestParameterBuilder paramJson(String name, Object value) throws UnsupportedEncodingException Adds a request parameter to the URL without specifying a data type of the given parameter value. Parameter's value is converted to JSON notation when adding. Furthermore, it will be encoded according to the acquired encoding.- Parameters:
name
- name of the request parametervalue
- value of the request parameter- Returns:
- RequestParameterBuilder updated this instance which can be reused
- Throws:
UnsupportedEncodingException
- DOCUMENT_ME
-
paramJson
public RequestParameterBuilder paramJson(String name, Object value, String type) throws UnsupportedEncodingException Adds a request parameter to the URL with specifying a data type of the given parameter value. Data type is sometimes required, especially for Java generic types, because type information is erased at runtime and the conversion to JSON will not work properly. Parameter's value is converted to JSON notation when adding. Furthermore, it will be encoded according to the acquired encoding.- Parameters:
name
- name of the request parametervalue
- value of the request parametertype
- data type of the value object. Any primitive type, array, non generic or generic type is supported. Data type is sometimes required to convert a value to a JSON representation. All data types should be fully qualified. Examples: "boolean" "int" "long[]" "java.lang.String" "java.util.Date" "java.util.Collection<java.lang.Integer>" "java.util.Map<java.lang.String, com.durr.FooPair<java.lang.Integer, java.util.Date>>" "com.durr.FooNonGenericClass" "com.durr.FooGenericClass<java.lang.String, java.lang.Integer>" "com.durr.FooGenericClass<int[], com.durr.FooGenericClass<com.durr.FooNonGenericClass, java.lang.Boolean>>".- Returns:
- RequestParameterBuilder updated this instance which can be reused
- Throws:
UnsupportedEncodingException
- DOCUMENT_ME
-
param
Adds a request parameter to the URL. This is a convenient method for primitive, plain data types. Parameter's value will not be converted to JSON notation when adding. It will be only encoded according to the acquired encoding. Note: null values will not be added.- Parameters:
name
- name of the request parametervalue
- value of the request parameter- Returns:
- RequestParameterBuilder updated this instance which can be reused
- Throws:
UnsupportedEncodingException
- DOCUMENT_ME
-
encode
Encodes given value with a proper encoding. This is a convenient method for primitive, plain data types. Value will not be converted to JSON. Note: Value can be null.- Parameters:
value
- value to be encoded- Returns:
- String encoded value
- Throws:
UnsupportedEncodingException
- DOCUMENT_ME
-
encodeJson
Convertes give value to JSON and encodes the converted value with a proper encoding. Data type is sometimes required, especially for Java generic types, because type information is erased at runtime and the conversion to JSON will not work properly.- Parameters:
value
- value to be converted and encodedtype
- data type of the value object. Any primitive type, array, non generic or generic type is supported. Data type is sometimes required to convert a value to a JSON representation. All data types should be fully qualified. Examples: "boolean" "int" "long[]" "java.lang.String" "java.util.Date" "java.util.Collection<java.lang.Integer>" "java.util.Map<java.lang.String, com.durr.FooPair<java.lang.Integer, java.util.Date>>" "com.durr.FooNonGenericClass" "com.durr.FooGenericClass<java.lang.String, java.lang.Integer>" "com.durr.FooGenericClass<int[], com.durr.FooGenericClass<com.durr.FooNonGenericClass, java.lang.Boolean>>".- Returns:
- String converted and encoded value
- Throws:
UnsupportedEncodingException
- DOCUMENT_ME
-
encodeJson
Convertes give value to JSON without to know the data type and encodes the converted value with a proper encoding.- Parameters:
value
- value to be converted and encoded- Returns:
- String converted and encoded value
- Throws:
UnsupportedEncodingException
- DOCUMENT_ME
-
build
Builds the end result.- Returns:
- String end result
-
reset
Resets the internal state in order to be reused.- Returns:
- RequestParameterBuilder reseted builder
-