Class AbstractJsonServerAction<T>

java.lang.Object
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.ServletRequestAware, org.apache.struts2.action.ServletResponseAware

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:
  • 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 com.opensymphony.xwork2.Action
      Overrides:
      execute in class com.opensymphony.xwork2.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