org.riotfamily.forms.controller
Class AbstractFormController

java.lang.Object
  extended by org.riotfamily.forms.controller.AbstractFormController
All Implemented Interfaces:
Controller
Direct Known Subclasses:
AjaxFormController

public abstract class AbstractFormController
extends Object
implements Controller

Abstract base class for controllers that display a form.

Author:
Felix Gnass [fgnass at neteye dot de]

Field Summary
protected static String BUTTON_CONTAINER_ID
           
static String FORM_SUBMISSION_HANDLER
           
protected  RiotLog log
           
 
Constructor Summary
AbstractFormController()
           
 
Method Summary
protected  Form createAndInitForm(HttpServletRequest request, HttpServletResponse response)
          Creates and initializes a form.
protected abstract  Form createForm(HttpServletRequest request)
          Subclasses must implement this method and return a fresh Form instance.
protected  ModelAndView createModelAndView(Form form, HttpServletRequest request, HttpServletResponse response)
           
protected  Form getForm(HttpServletRequest request)
          Returns the Form for the given request.
protected  Object getFormBackingObject(HttpServletRequest request)
          Returns the object backing the form.
protected  String getSessionAttribute(HttpServletRequest request)
          Returns the name of the attribute under which the Form is stored in the HTTP session.
protected  PrintWriter getWriter(HttpServletRequest request, HttpServletResponse response)
           
protected  ModelAndView handleContentRequest(Form form, HttpServletRequest request, HttpServletResponse response)
           
protected  ModelAndView handleFormRequest(Form form, HttpServletRequest request, HttpServletResponse response)
           
protected abstract  ModelAndView handleFormSubmission(Form form, HttpServletRequest request, HttpServletResponse response)
           
 ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
          Handles a HTTP request.
protected  void initController()
           
protected  void initForm(Form form, HttpServletRequest request)
          Subclasses may overwrite this method to initialize forms after they have been populated.
protected  boolean isContentRequest(HttpServletRequest request)
          Returns whether the request is to be handled by a ContentElement.
protected  boolean isExclusiveRequest(HttpServletRequest request)
           
protected  boolean isInitialRequest(HttpServletRequest request)
          Returns whether the given request is an initial form request.
protected  void populateForm(Form form, HttpServletRequest request)
          Populates newly created forms.
protected  void processForm(Form form, HttpServletRequest request)
           
protected  void removeFormFromSession(HttpServletRequest request)
          Removes the Form from the HTTP session.
protected  void renderForm(Form form, PrintWriter writer)
           
 void setFormContextFactory(FormContextFactory contextFactory)
           
 void setProcessNewForms(boolean processNewForms)
           
protected  ModelAndView showForm(Form form, HttpServletRequest request, HttpServletResponse response)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FORM_SUBMISSION_HANDLER

public static final String FORM_SUBMISSION_HANDLER
See Also:
Constant Field Values

BUTTON_CONTAINER_ID

protected static final String BUTTON_CONTAINER_ID
See Also:
Constant Field Values

log

protected RiotLog log
Constructor Detail

AbstractFormController

public AbstractFormController()
Method Detail

setFormContextFactory

public void setFormContextFactory(FormContextFactory contextFactory)

setProcessNewForms

public final void setProcessNewForms(boolean processNewForms)

initController

protected final void initController()

handleRequest

public ModelAndView handleRequest(HttpServletRequest request,
                                  HttpServletResponse response)
                           throws Exception
Handles a HTTP request. The workflow is:
  1. Check if a new Form needs to be created by calling isInitialRequest(javax.servlet.http.HttpServletRequest).
  2. Call to createAndInitForm(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) in case of an initial request or getForm(javax.servlet.http.HttpServletRequest) otherwise.
  3. Check if the request is request for additional content (an image or iframe for example) and call handleContentRequest(org.riotfamily.forms.Form, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) or handleFormRequest(org.riotfamily.forms.Form, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse).

Specified by:
handleRequest in interface Controller
Throws:
Exception

handleFormRequest

protected ModelAndView handleFormRequest(Form form,
                                         HttpServletRequest request,
                                         HttpServletResponse response)
                                  throws Exception
Throws:
Exception

getForm

protected Form getForm(HttpServletRequest request)
Returns the Form for the given request. By default this method looks for an existing instance in the HTTP session under the key returned by getSessionAttribute(javax.servlet.http.HttpServletRequest) and returns it.


showForm

protected ModelAndView showForm(Form form,
                                HttpServletRequest request,
                                HttpServletResponse response)
                         throws Exception
Throws:
Exception

getWriter

protected PrintWriter getWriter(HttpServletRequest request,
                                HttpServletResponse response)
                         throws IOException
Throws:
IOException

renderForm

protected void renderForm(Form form,
                          PrintWriter writer)

isInitialRequest

protected boolean isInitialRequest(HttpServletRequest request)
Returns whether the given request is an initial form request. By default it is checked whether the request method is GET and isContentRequest(javax.servlet.http.HttpServletRequest) returns false.


isContentRequest

protected boolean isContentRequest(HttpServletRequest request)
Returns whether the request is to be handled by a ContentElement.


isExclusiveRequest

protected boolean isExclusiveRequest(HttpServletRequest request)

handleContentRequest

protected ModelAndView handleContentRequest(Form form,
                                            HttpServletRequest request,
                                            HttpServletResponse response)
                                     throws IOException
Throws:
IOException

createAndInitForm

protected Form createAndInitForm(HttpServletRequest request,
                                 HttpServletResponse response)
                          throws Exception
Creates and initializes a form.

Throws:
Exception

processForm

protected void processForm(Form form,
                           HttpServletRequest request)

populateForm

protected void populateForm(Form form,
                            HttpServletRequest request)
                     throws Exception
Populates newly created forms. The default implementation invokes Form#setValue(Object) with the object returned by getFormBackingObject(HttpServletRequest).

Throws:
Exception

getFormBackingObject

protected Object getFormBackingObject(HttpServletRequest request)
                               throws Exception
Returns the object backing the form. Subclasses may overwrite this method to retrieve a persistent object. The default implementation returns null.

Throws:
Exception

createForm

protected abstract Form createForm(HttpServletRequest request)
Subclasses must implement this method and return a fresh Form instance.


initForm

protected void initForm(Form form,
                        HttpServletRequest request)
Subclasses may overwrite this method to initialize forms after they have been populated. The default implementation does nothing.


createModelAndView

protected final ModelAndView createModelAndView(Form form,
                                                HttpServletRequest request,
                                                HttpServletResponse response)
                                         throws Exception
Throws:
Exception

handleFormSubmission

protected abstract ModelAndView handleFormSubmission(Form form,
                                                     HttpServletRequest request,
                                                     HttpServletResponse response)
                                              throws Exception
Throws:
Exception

getSessionAttribute

protected String getSessionAttribute(HttpServletRequest request)
Returns the name of the attribute under which the Form is stored in the HTTP session.


removeFormFromSession

protected void removeFormFromSession(HttpServletRequest request)
Removes the Form from the HTTP session.