Class RequestParameterBuilder

java.lang.Object
org.primefaces.extensions.util.RequestParameterBuilder

public class RequestParameterBuilder extends Object
Builder for request parameters.
Since:
1.1.0
Author:
Oleg Varaksin
  • 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

      public RequestParameterBuilder(String url)
      Creates a builder instance by the given URL.
      Parameters:
      url - URL
    • RequestParameterBuilder

      public RequestParameterBuilder(String url, JsonConverter jsonConverter)
      Creates a builder instance by the given URL.
      Parameters:
      url - URL
      jsonConverter - specific JsonConverter. It should extends JsonConverter from PrimeFaces Extensions. If null, the default implementation JsonExposeAwareConverter 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 parameter
      value - 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 parameter
      value - value of the request parameter
      type - 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 parameter
      value - value of the request parameter
      Returns:
      RequestParameterBuilder updated this instance which can be reused
      Throws:
      UnsupportedEncodingException - DOCUMENT_ME
    • encode

      public String encode(Object value) throws UnsupportedEncodingException
      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

      public String encodeJson(Object value, String type) throws UnsupportedEncodingException
      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 encoded
      type - 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

      public String encodeJson(Object value) throws UnsupportedEncodingException
      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

      public 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