com.isomorphic.rpc

## Class RPCResponse

- com.isomorphic.rpc.RPCResponse

-     public class RPCResponse

  RPCResponse encapsulates data sent from the server to the client in response to an RPCRequest.
  See Also:
    `RPCManager`, `RPCRequest`, `JSTranslater`

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `STATUS_FAILURE` Indicates a failure of some sort (generic).
    `static int` | `STATUS_SUCCESS` Indicates successful completion of the request.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `RPCResponse()` Creates an empty RPCResponse.
    `RPCResponse(java.lang.Object data)` Creates an RPCResponse with the provided data payload. Note: the status of this response is automatically set to the success code (RPCResponse.STATUS_SUCCESS)

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `java.lang.Object` | `getData()` Retrives the data previosly set via setData() or the constructor that takes the data argument.
    `int` | `getStatus()` Retrieves the currently set status code for this response.
    `RPCResponse` | `setData(java.lang.Object data)` Sets the response payload to be delivered to the client.
    `RPCResponse` | `setStatus(int status)` Sets the status of this response.

- - ### Field Detail

    - #### STATUS_SUCCESS

          public static final int STATUS_SUCCESS

      Indicates successful completion of the request. This is the default status and is automatically used by the RPCResponse unless you override it with setStatus().

    - #### STATUS_FAILURE

          public static final int STATUS_FAILURE

      Indicates a failure of some sort (generic).

      See the error handling doc section in RPCManager for information on how the client handles errors.

  - ### Constructor Detail

    - #### RPCResponse

          public RPCResponse()

      Creates an empty RPCResponse. If you use this constructor, you will need to call setData() to set the data you wish to be sent back to the client.

      Note: the status of this response is automatically set to the success code (RPCResponse.STATUS_SUCCESS); response is set to a success code (0)

      Parameters:
        `data` - the data you wish to send back.

    - #### RPCResponse

          public RPCResponse(java.lang.Object data)

      Creates an RPCResponse with the provided data payload.
      Note: the status of this response is automatically set to the success code (RPCResponse.STATUS_SUCCESS)
      Parameters:
        `data` - the data you wish to send back.
      See Also:
        `RPCResponse.setData(Object)`

  - ### Method Detail

    - #### getData

          public java.lang.Object getData()

      Retrives the data previosly set via setData() or the constructor that takes the data argument.

    - #### setData

          public RPCResponse setData(java.lang.Object data)

      Sets the response payload to be delivered to the client.

      The object passed to setData() is translated to JavaScript via the JSTranslater class. Virtually anything passed to setData() will make it back to the browser in some reasonable representation; see JSTranslater for full documentation.

      You may call setData() any number of times, only the last provided value will be the value sent to the client.

      Parameters:
        `data` - the data you wish to send back.
      Returns:
        the RPCResponse
      See Also:
        `JSTranslater.toJS(Object, Writer)`, `JSONFilter`

    - #### setStatus

          public RPCResponse setStatus(int status)

      Sets the status of this response. A zero status indicates succeess, a negative value indicates failure.

      Negative values will trigger error handling code on the client side - see the client-side reference for RPCManager.handleError(), rpcRequest.willHandleError.

      The default client-side behavior for a negative status code is that, if the data sent back (via setData()) is a String, it will be shown to the user in a warning dialog.

      Parameters:
        `status` - the status code for this response
      Returns:
        the RPCResponse

    - #### getStatus

          public int getStatus()

      Retrieves the currently set status code for this response.