Class JsonDatasourceAttribute

java.lang.Object
org.mapfish.print.attribute.JsonDatasourceAttribute
All Implemented Interfaces:
Attribute, ConfigurationObject

public class JsonDatasourceAttribute extends Object implements Attribute
A JSON data source attribute. To be declared as net.sf.jasperreports.engine.data.JsonDataSource in Jasper. Accepts only JSON objects at the root. To use it, you must pass it to a sub report like that:

 < subreport>
     ...
     < dataSourceExpression>
         < ![CDATA[$P{json_attribute}.subDataSource("path.to.list")]]>
     < /dataSourceExpression>
     < subreportExpression><![CDATA["subreport_name.jasper"]]>< /subreportExpression>
 < /subreport>
 

The expression given to the subDataSource method must select an array in the JSON structure.

  • Constructor Details

    • JsonDatasourceAttribute

      public JsonDatasourceAttribute()
  • Method Details

    • printClientConfig

      public void printClientConfig(org.json.JSONWriter json, Template template) throws org.json.JSONException
      Description copied from interface: Attribute
      Write this attribute out the the json writer so that clients can know what attributes are expected.
      Specified by:
      printClientConfig in interface Attribute
      Parameters:
      json - the json writer to write to
      template - the template that this attribute is part of
      Throws:
      org.json.JSONException
    • setConfigName

      public void setConfigName(String name)
      Description copied from interface: Attribute
      Set the name of the attribute as set in the configuration file.
      Specified by:
      setConfigName in interface Attribute
      Parameters:
      name - the name of the attribute
    • getValueType

      public Class getValueType()
      Description copied from interface: Attribute
      Get the class of the value.
      Specified by:
      getValueType in interface Attribute
      Returns:
      the value class
    • getValue

      public Object getValue(@Nonnull Template template, @Nonnull String attributeName, @Nonnull PObject requestJsonAttributes)
      Description copied from interface: Attribute
      Get the attribute value.
      Specified by:
      getValue in interface Attribute
      Parameters:
      template - the template of the current request.
      attributeName - the name of the attribute
      requestJsonAttributes - the json data for populating the attribute values
      Returns:
      the value
    • validate

      public void validate(List<Throwable> validationErrors, Configuration configuration)
      Description copied from interface: ConfigurationObject
      validate that the configuration was correct.
      Specified by:
      validate in interface ConfigurationObject
      Parameters:
      validationErrors - a list to add any detected errors to.
      configuration - the containing configuration