Class JsonDatasourceAttribute

  • All Implemented Interfaces:
    Attribute, ConfigurationObject

    public class JsonDatasourceAttribute
    extends java.lang.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.

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Object getValue​(Template template, java.lang.String attributeName, PObject requestJsonAttributes)
      Get the attribute value.
      java.lang.Class getValueType()
      Get the class of the value.
      void printClientConfig​(org.json.JSONWriter json, Template template)
      Write this attribute out the the json writer so that clients can know what attributes are expected.
      void setConfigName​(java.lang.String name)
      Set the name of the attribute as set in the configuration file.
      void validate​(java.util.List<java.lang.Throwable> validationErrors, Configuration configuration)
      validate that the configuration was correct.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • JsonDatasourceAttribute

        public JsonDatasourceAttribute()
    • Method Detail

      • 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​(java.lang.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 java.lang.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 java.lang.Object getValue​(@Nonnull
                                         Template template,
                                         @Nonnull
                                         java.lang.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​(java.util.List<java.lang.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