java.lang.Object
org.apache.struts.action.Action
org.apache.struts.actions.BaseAction
org.apache.struts.actions.DispatchAction
org.apache.struts.actions.MappingDispatchAction
com.echothree.view.client.web.struts.sprout.Sprout

public abstract class Sprout extends org.apache.struts.actions.MappingDispatchAction

One goal is to make web application development in Java more fun. Sprouts require Java 5 (1.5) due to their use of annotations. They also require a servlet engine conforming to the Servlet 2.4 and JSP 2.0 specs (Tomcat 5.x, for example) due to the use of filters, listeners, and tag files.

Sprouts obviate the need to write Struts action-mappings as they use information gleaned from the initial Sprout, class properties (name and package), as well as annotations to appropriately self-register on URLs defined by convention or specification with properties obtained the same way.

The path is determined by the package name where the components to the right of "action" are converted into directories. Thus, whatever.action.* will correspond to /* and whatever.action.help.* to /help/*

The file (or action) is determined by the method name. Thus, index() will correspond to index.do and submitChange() to submit_change (CamelCased method names are converted).

(NOTE: publick() maps to public.do as public is a Java keyword.)

Form names are created from the class name appended with Form, so TestAction would default to TestActionForm. This behavior can be overridden using the @FormName("AlternateForm") annotation.

Input, validate, and scope properties can be overridden with @Input, @Validate, and @Scope respectively.

f(key), F(key), and s(key,value) are helper methods that manipulate DynaActionForms (if used) and obviate the need to cast excessively. f() is the equivalent of calling getString(), F() get(), and s() set().

getMessages(), getErrors(), saveMessages(), and saveErrors() have been modified to store state in the user's session allowing them to be used more simply and effectively. Rather than using this:

   ActionMessages errors = new ActionMessages();
   ...
   saveErrors(request, errors);
 
You should use getErrors() to initialize the errors ActionMessages object:
   ActionMessages errors = getErrors( request );
   ...
 
This way, messages and errors can be stacked up (while being kept separate) until they are displayed using the sprout:notifications taglib (see WEB-INF/tags/sprout/notifications.tag).

TODO add additional reserved words
TODO add a default ActionForm with just an "id" field (as a String) as "SproutForm"
TODO add a GlobalForward annotation with "redirect" property to add to the
list of global-forwards.
TODO add some measure of SiteMesh integration for AJAX partials
TODO add some form of ActionForwardBuilder

Author:
Seth Fitzsimmons
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    protected static @interface 
    Override the default form name for this action.
    protected static @interface 
    Specifies a local forward.
    protected static @interface 
    Specifies the "input" property for this action.
    protected static @interface 
    Specifies the "scope" property for this action.
    protected static @interface 
    Instruct Struts to validate the form provided to this method.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Default forward key.
    static final String
     

    Fields inherited from class org.apache.struts.actions.DispatchAction

    clazz, methods, types

    Fields inherited from class org.apache.struts.actions.BaseAction

    messages

    Fields inherited from class org.apache.struts.action.Action

    servlet
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    addErrors(javax.servlet.http.HttpServletRequest request, org.apache.struts.action.ActionMessages msgs)
    Add errors to the session.
    protected void
    addMessages(javax.servlet.http.HttpServletRequest request, org.apache.struts.action.ActionMessages msgs)
    Add messages to the session.
    protected String
    f(String key)
    Shortcut for ((DynaActionForm) form).getString(key).
    protected Object
    F(String key)
    Shortcut for ((DynaActionForm) form).get(key).
    protected org.apache.struts.action.ActionMessages
    getErrors(javax.servlet.http.HttpServletRequest request)
    Gets undisplayed errors from both the request and the session.
    protected org.apache.struts.action.ActionMessages
    getMessages(javax.servlet.http.HttpServletRequest request)
    Gets undisplayed messages from both the request and the session.
    org.apache.struts.action.ActionForward
    index(org.apache.struts.action.ActionMapping mapping, org.apache.struts.action.ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
    Helper method to display index.jsp in response to a request for /index.do
    final void
    init(org.apache.struts.action.ActionMapping mapping, org.apache.struts.action.ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
     
    protected void
    onInit(org.apache.struts.action.ActionMapping mapping, org.apache.struts.action.ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
    Callback for subclass-specific initialization.
    protected void
    s(String key, Object value)
    Shortcut for ((DynaActionForm) form).set(key, value).
    protected void
    saveErrors(javax.servlet.http.HttpServletRequest request, org.apache.struts.action.ActionMessages msgs)
    Saves errors to the session scope so that they may be picked up by the next action that accesses errors.
    protected void
    saveMessages(javax.servlet.http.HttpServletRequest request, org.apache.struts.action.ActionMessages msgs)
    Saves messages to the session scope so that they may be picked up by the next action that accesses messages.

    Methods inherited from class org.apache.struts.actions.MappingDispatchAction

    execute, getMethodName, getParameter, unspecified

    Methods inherited from class org.apache.struts.actions.DispatchAction

    cancelled, dispatchMethod, getMethod

    Methods inherited from class org.apache.struts.action.Action

    execute, generateToken, getLocale, getResources, getResources, getServlet, isCancelled, isTokenValid, isTokenValid, resetToken, saveErrors, saveMessages, saveToken, setLocale, setServlet

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

  • Method Details

    • init

      public final void init(org.apache.struts.action.ActionMapping mapping, org.apache.struts.action.ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
    • onInit

      protected void onInit(org.apache.struts.action.ActionMapping mapping, org.apache.struts.action.ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
      Callback for subclass-specific initialization.
    • f

      protected String f(String key)
      Shortcut for ((DynaActionForm) form).getString(key).
    • F

      protected Object F(String key)
      Shortcut for ((DynaActionForm) form).get(key).
    • s

      protected void s(String key, Object value)
      Shortcut for ((DynaActionForm) form).set(key, value).
    • addErrors

      protected void addErrors(javax.servlet.http.HttpServletRequest request, org.apache.struts.action.ActionMessages msgs)
      Add errors to the session.
      Overrides:
      addErrors in class org.apache.struts.action.Action
    • getErrors

      protected org.apache.struts.action.ActionMessages getErrors(javax.servlet.http.HttpServletRequest request)
      Gets undisplayed errors from both the request and the session.
      Overrides:
      getErrors in class org.apache.struts.action.Action
    • saveErrors

      protected void saveErrors(javax.servlet.http.HttpServletRequest request, org.apache.struts.action.ActionMessages msgs)
      Saves errors to the session scope so that they may be picked up by the next action that accesses errors.
      Overrides:
      saveErrors in class org.apache.struts.action.Action
    • addMessages

      protected void addMessages(javax.servlet.http.HttpServletRequest request, org.apache.struts.action.ActionMessages msgs)
      Add messages to the session.
      Overrides:
      addMessages in class org.apache.struts.action.Action
    • getMessages

      protected org.apache.struts.action.ActionMessages getMessages(javax.servlet.http.HttpServletRequest request)
      Gets undisplayed messages from both the request and the session.
      Overrides:
      getMessages in class org.apache.struts.action.Action
    • saveMessages

      protected void saveMessages(javax.servlet.http.HttpServletRequest request, org.apache.struts.action.ActionMessages msgs)
      Saves messages to the session scope so that they may be picked up by the next action that accesses messages.
      Overrides:
      saveMessages in class org.apache.struts.action.Action
    • index

      public org.apache.struts.action.ActionForward index(org.apache.struts.action.ActionMapping mapping, org.apache.struts.action.ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws IOException, javax.servlet.ServletException
      Helper method to display index.jsp in response to a request for /index.do
      Throws:
      IOException
      javax.servlet.ServletException