com.opensymphony.webwork.dispatcher.json
Class JSONResult

java.lang.Object
  extended by com.opensymphony.webwork.dispatcher.json.JSONResult
All Implemented Interfaces:
Result, Serializable

public class JSONResult
extends Object
implements Result

Attempt to retrieve an instance of JSONObject from WebWork's ValueStack through property returned from getJSONObjectProperty() and write the String representation of the retrived JSONObject to HttpServletResponse's outputstream. Normally having accessor methods for the property in WebWork's action would do the trick.

 

  <action name="getActiveCustomers" class="...">
      <result name="success" type="json">
          <param name="jsonObjectProperty">activeCustomer</param>
          <param name="contentType">application/json</param>
      </result>
      ...
  </action>>

  Or just

  <action name="getActiveCustomers" class="...">
      <result name="success" type="json" />
      ...
  </action>

  if we used the default property ('jsonObject') and default content-type ('application/json')

 
 

Version:
$Date$ $Id$
Author:
tmjee
See Also:
Serialized Form

Constructor Summary
JSONResult()
           
 
Method Summary
 void execute(ActionInvocation invocation)
          Writes the string representation of JSONObject defined through getJSONObjectProperty() to HttpServletResponse's outputstream.
 String getContentType()
          Returns the content-type header to be used.
protected  JSONObject getJSONObject(ActionInvocation invocation)
          Attempt to look up a JSONObject instance through the property (getJSONObjectProperty()) by looking up the property in WebWork's ValueStack.
 String getJSONObjectProperty()
          Returns the property which will be used to lookup JSONObject in WebWork's ValueStack.
protected  HttpServletResponse getServletResponse(ActionInvocation invocation)
          Returns a HttpServletResponse by looking it up through WebWork's ActionContext Map.
 void setContentType(String contentType)
          Set the content-type header to be used.
 void setJSONObjectProperty(String jsonObject)
          Set the property which will be used to lookup JSONObject in WebWork's ValueStack.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JSONResult

public JSONResult()
Method Detail

getJSONObjectProperty

public String getJSONObjectProperty()
Returns the property which will be used to lookup JSONObject in WebWork's ValueStack. Default to 'jsonObject'.

Returns:
String

setJSONObjectProperty

public void setJSONObjectProperty(String jsonObject)
Set the property which will be used to lookup JSONObject in WebWork's ValueStack. Default to 'jsonObject'.

Parameters:
jsonObject -

getContentType

public String getContentType()
Returns the content-type header to be used. Default to 'application/json'.

Returns:
String

setContentType

public void setContentType(String contentType)
Set the content-type header to be used. Default to 'application/json'.

Parameters:
contentType -

execute

public void execute(ActionInvocation invocation)
             throws Exception
Writes the string representation of JSONObject defined through getJSONObjectProperty() to HttpServletResponse's outputstream.

Specified by:
execute in interface Result
Parameters:
invocation -
Throws:
Exception

getJSONObject

protected JSONObject getJSONObject(ActionInvocation invocation)
                            throws JSONException
Attempt to look up a JSONObject instance through the property (getJSONObjectProperty()) by looking up the property in WebWork's ValueStack. It shall be found if there's accessor method for the property in WebWork's action itself.

Returns null if one cannot be found.

We could override this method to return the desired JSONObject when writing testcases.

Parameters:
invocation -
Returns:
JSONObject or null if one cannot be found
Throws:
JSONException

getServletResponse

protected HttpServletResponse getServletResponse(ActionInvocation invocation)
Returns a HttpServletResponse by looking it up through WebWork's ActionContext Map.

We could override this method to return the desired Mock HttpServletResponse when writing testcases.

Parameters:
invocation -
Returns:
HttpServletResponse

WebWork Project Page