Class JSONArrayRequestParameter

java.lang.Object
com.invirgance.convirgance.web.parameter.JSONArrayRequestParameter
All Implemented Interfaces:
Parameter

@Wiring public class JSONArrayRequestParameter extends Object implements Parameter
A mechanism for converting multiple HTML form input elements with the same name into an array of objects that can be processed by Convirgance.

For example, a sequence of suggested scheduling dates might look like this:

 <div>
     <input type="date" name="available_date" value="2025-02-10">
     <select name="time_of_day">
         <option selected>Morning</option>
         <option>Afternoon</option>
         <option>Evening</option>
     </select>
 </div>
 <div>
     <input type="date" name="available_date" value="2025-02-12">
     <select name="time_of_day">
         <option>Morning</option>
         <option>Afternoon</option>
         <option selected>Evening</option>
     </select>
 </div>
 
The submitted form would contain the values in order, like this:

 available_date=2025-02-10&time_of_day=Morning&available_date=2025-02-12&time_of_day=Evening
 
Using this Parameter with the available_date and time_of_day keys like this:

 <JSONArrayRequestParameter>
     <name>fields</name>
     <keys>available_date,time_of_day</keys>
 </JSONArrayRequestParameter>
 
...results in the following value being returned:

 [
     {"available_date": "2025-02-10", "time_of_day": "Morning"},
     {"available_date": "2025-02-12", "time_of_day": "Evening"}
 ]
 
This list of records could then be processed using the <children> feature in the QueryConsumer or UpdateService features.
Author:
jbanes
  • Constructor Details

    • JSONArrayRequestParameter

      public JSONArrayRequestParameter()
  • Method Details

    • getName

      public String getName()
      Description copied from interface: Parameter
      Gets the name of this parameter.
      Specified by:
      getName in interface Parameter
      Returns:
      The parameter name
    • setName

      public void setName(String name)
      Sets the name of the parameter to return
      Parameters:
      name - the name of the parameter
    • getKeys

      public String[] getKeys()
      Get the array of parameter names that will be read into the array
      Returns:
      an array of parameter names
    • setKeys

      public void setKeys(String[] keys)
      Set a list of request parameter names that will be included in the array. Note that the parameter names must appear the same number of times in the correct order to ensure that the values are correctly decoded into the correct object in the JSONArray.
      Parameters:
      keys -
    • getValue

      public Object getValue(HttpRequest request)
      Description copied from interface: Parameter
      Extracts a value from the HTTP request.
      Specified by:
      getValue in interface Parameter
      Parameters:
      request - The HTTP request to extract values from
      Returns:
      The extracted value