Class JsonReaderResponse<T>

  • Type Parameters:
    T - Type of Objects that will be converted to Ext.data.Records by the client-side Ext.data.DataReader.

    public class JsonReaderResponse<T>
    extends Object
    Creates a response that can be consumed by an Ext.data.JsonReader. The client-side Ext.data.JsonReader must have the "root" property set to "records". Note: Ext documentation often uses "rows" for this property, but "records" is more clear. Example Ext.data.JsonReader configuration:
     {
      root : 'records',
      successProperty : 'success', // same as default.
      messageProperty : 'message',
      totalProperty : 'totalRecords'
     }
     
    If the parameterized type has two properties "field1" and "field2", then when an instance of this class is read by the client and there are 100 records in total to page through, it will look like:
      {
          records : [
              {
                  field1 : 'value',
                  field2 : 'value',
              }, {
                  field1 : 'value',
                  field2 : 'value',
              }
          ],
          success : true,
          totalRecords : 100,  // Only needed if you are paging.
          message : "Yay!" // optional.
     }
     
    Note that for Gemma, 'success' is rarely all that useful because even though DWR will always (?) return a 200, the error handler gets called.
    Author:
    paul (based on http://github.com/BigLep/ExtJsWithDwr/)
    • Field Detail

      • message

        public String message
      • success

        public boolean success
      • totalRecords

        public long totalRecords
    • Constructor Detail

      • JsonReaderResponse

        public JsonReaderResponse​(List<T> objectsToConvertToRecords)
        Creates a successful JsonReaderResponse with the provided objectsToConvertToRecords. The totalRecords is assumed to be the length of objectsToConvertToRecords
      • JsonReaderResponse

        public JsonReaderResponse​(Collection<T> objectsToConvertToRecords,
                                  long totalRecords)
        Use for remote paging applications. Creates a successful JsonReaderResponse with the provided objectsToConvertToRecords.
        Parameters:
        objectsToConvertToRecords - objects to convert
        totalRecords - total records
      • JsonReaderResponse

        public JsonReaderResponse​(String message)
        Creates an unsuccessful JsonReaderResponse with null records. This signals the case where the client established a connection with the server, but the server couldn't fulfill it (e.g., user doesn't have proper user credentials).
        Parameters:
        message - an error message to give to the client.
    • Method Detail

      • getMessage

        public String getMessage()
        Returns:
        the message
      • setMessage

        public void setMessage​(String message)
        Parameters:
        message - the message to set
      • getRecords

        public Collection<T> getRecords()
        Returns:
        the records
      • setRecords

        public void setRecords​(List<T> records)
        Parameters:
        records - the records to set
      • getTotalRecords

        public long getTotalRecords()
        Returns:
        the totalRecords
      • setTotalRecords

        public void setTotalRecords​(long totalRecords)
        Parameters:
        totalRecords - the totalRecords to set
      • isSuccess

        public boolean isSuccess()
        Returns:
        the success
      • setSuccess

        public void setSuccess​(boolean success)
        Parameters:
        success - the success to set