Package org.primefaces.extensions.util
Class RequestParameterBuilder
- java.lang.Object
-
- org.primefaces.extensions.util.RequestParameterBuilder
-
public class RequestParameterBuilder extends java.lang.ObjectBuilder for request parameters.- Since:
- 1.1.0
- Author:
- Oleg Varaksin
-
-
Constructor Summary
Constructors Constructor Description RequestParameterBuilder()Creates a builder instance.RequestParameterBuilder(boolean useCurrentRequest)Creates a builder instance wihout URL or with the current request URL.RequestParameterBuilder(java.lang.String url)Creates a builder instance by the given URL.RequestParameterBuilder(java.lang.String url, JsonConverter jsonConverter)Creates a builder instance by the given URL.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Stringbuild()Builds the end result.java.lang.Stringencode(java.lang.Object value)Encodes given value with a proper encoding.java.lang.StringencodeJson(java.lang.Object value)Convertes give value to JSON without to know the data type and encodes the converted value with a proper encoding.java.lang.StringencodeJson(java.lang.Object value, java.lang.String type)Convertes give value to JSON and encodes the converted value with a proper encoding.RequestParameterBuilderparam(java.lang.String name, java.lang.Object value)Adds a request parameter to the URL.RequestParameterBuilderparamJson(java.lang.String name, java.lang.Object value)Adds a request parameter to the URL without specifying a data type of the given parameter value.RequestParameterBuilderparamJson(java.lang.String name, java.lang.Object value, java.lang.String type)Adds a request parameter to the URL with specifying a data type of the given parameter value.RequestParameterBuilderreset()Resets the internal state in order to be reused.
-
-
-
Constructor Detail
-
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
public RequestParameterBuilder(java.lang.String url)
Creates a builder instance by the given URL.- Parameters:
url- URL
-
RequestParameterBuilder
public RequestParameterBuilder(java.lang.String url, JsonConverter jsonConverter)Creates a builder instance by the given URL.- Parameters:
url- URLjsonConverter- specific JsonConverter. It should extendsJsonConverterfrom PrimeFaces Extensions. If null, the default implementationJsonExposeAwareConverteris used.
-
-
Method Detail
-
paramJson
public RequestParameterBuilder paramJson(java.lang.String name, java.lang.Object value) throws java.io.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:
java.io.UnsupportedEncodingException- DOCUMENT_ME
-
paramJson
public RequestParameterBuilder paramJson(java.lang.String name, java.lang.Object value, java.lang.String type) throws java.io.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:
java.io.UnsupportedEncodingException- DOCUMENT_ME
-
param
public RequestParameterBuilder param(java.lang.String name, java.lang.Object value) throws java.io.UnsupportedEncodingException
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:
java.io.UnsupportedEncodingException- DOCUMENT_ME
-
encode
public java.lang.String encode(java.lang.Object value) throws java.io.UnsupportedEncodingExceptionEncodes 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:
java.io.UnsupportedEncodingException- DOCUMENT_ME
-
encodeJson
public java.lang.String encodeJson(java.lang.Object value, java.lang.String type) throws java.io.UnsupportedEncodingExceptionConvertes 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:
java.io.UnsupportedEncodingException- DOCUMENT_ME
-
encodeJson
public java.lang.String encodeJson(java.lang.Object value) throws java.io.UnsupportedEncodingExceptionConvertes 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:
java.io.UnsupportedEncodingException- DOCUMENT_ME
-
build
public java.lang.String build()
Builds the end result.- Returns:
- String end result
-
reset
public RequestParameterBuilder reset()
Resets the internal state in order to be reused.- Returns:
- RequestParameterBuilder reseted builder
-
-