Class AbstractJsonServerAction<T>

java.lang.Object
org.apache.struts2.ActionSupport
com.opensymphony.xwork2.ActionSupport
name.matthewgreet.strutscommons.action.AbstractActionSupport
name.matthewgreet.strutscommons.action.AbstractJsonServerAction<T>
Type Parameters:
T - Type to convert to JSON.
All Implemented Interfaces:
com.opensymphony.xwork2.Action, com.opensymphony.xwork2.interceptor.ValidationAware, com.opensymphony.xwork2.LocaleProvider, com.opensymphony.xwork2.TextProvider, com.opensymphony.xwork2.Validateable, Serializable, BrowserTabAware, BrowserTabAware2, org.apache.struts2.action.Action, org.apache.struts2.action.ServletRequestAware, org.apache.struts2.action.ServletResponseAware, org.apache.struts2.interceptor.ValidationAware, org.apache.struts2.Validateable

public abstract class AbstractJsonServerAction<T> extends AbstractActionSupport implements org.apache.struts2.action.ServletResponseAware

Template class of Struts 2 action for serving Json data of generic type T, usually for JQuery-based pages using jQuery.getJSON.

The following is an example for generic type T:

   public static class ProcessParamItem {
       @JsonProperty("value")
       private String value;
       

       public String getValue() {
           return value;
       }
       public void setValue(String value) {
           this.value = value;
       }
        
       public String toString() {
           return "ProcessParamItem [value=" + value + "]";
       }
   }
 
See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from interface com.opensymphony.xwork2.interceptor.ValidationAware

    com.opensymphony.xwork2.interceptor.ValidationAware.LegacyAdapter
  • Field Summary

    Fields inherited from class org.apache.struts2.ActionSupport

    container

    Fields inherited from interface org.apache.struts2.action.Action

    ERROR, INPUT, LOGIN, NONE, SUCCESS
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
     
    protected String
    Can be overridden to set execute result if it fails.
    javax.servlet.http.HttpServletResponse
     
    protected abstract T
     
    void
    withServletResponse(javax.servlet.http.HttpServletResponse response)
     

    Methods inherited from class name.matthewgreet.strutscommons.action.AbstractActionSupport

    getBrowserTabSession, getServletRequest, getTabId, setBrowserTabSession, setTabId, withServletRequest

    Methods inherited from class org.apache.struts2.ActionSupport

    addActionError, addActionMessage, addFieldError, clearActionErrors, clearErrors, clearErrorsAndMessages, clearFieldErrors, clearMessages, clone, getActionErrors, getActionMessages, getContainer, getFieldErrors, getFormatted, getLocale, getLocaleProvider, getText, getText, getText, getText, getText, getText, getText, getText, getText, getTextProvider, getTexts, getTexts, hasActionErrors, hasActionMessages, hasErrors, hasFieldErrors, hasKey, input, isValidLocale, isValidLocaleString, pause, setActionErrors, setActionMessages, setContainer, setFieldErrors, toLocale, validate

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface name.matthewgreet.strutscommons.action.BrowserTabAware2

    copyAttributesFromOldTabToNewTab, handleAttributeFailures

    Methods inherited from interface org.apache.struts2.Validateable

    validate

    Methods inherited from interface org.apache.struts2.interceptor.ValidationAware

    addActionError, addActionMessage, addFieldError, getActionErrors, getActionMessages, getFieldErrors, hasActionErrors, hasActionMessages, hasErrors, hasFieldErrors, setActionErrors, setActionMessages, setFieldErrors
  • Constructor Details

    • AbstractJsonServerAction

      public AbstractJsonServerAction()
  • Method Details

    • getErrorResultName

      protected String getErrorResultName()
      Can be overridden to set execute result if it fails.
    • makeContent

      protected abstract T makeContent() throws Exception
      Throws:
      Exception
    • execute

      public String execute() throws Exception
      Specified by:
      execute in interface org.apache.struts2.action.Action
      Overrides:
      execute in class org.apache.struts2.ActionSupport
      Throws:
      Exception
    • getResponse

      public javax.servlet.http.HttpServletResponse getResponse()
    • withServletResponse

      public void withServletResponse(javax.servlet.http.HttpServletResponse response)
      Specified by:
      withServletResponse in interface org.apache.struts2.action.ServletResponseAware