net.sourceforge.stripes.tag
Class DefaultPopulationStrategy

java.lang.Object
  extended by net.sourceforge.stripes.tag.DefaultPopulationStrategy
All Implemented Interfaces:
ConfigurableComponent, PopulationStrategy
Direct Known Subclasses:
BeanFirstPopulationStrategy

public class DefaultPopulationStrategy
extends Object
implements PopulationStrategy

Default implementation of the form input tag population strategy. First looks to see if there is a parameter with the same name as the tag submitted in the current request. If there is, it will be returned as a String[] in order to support multiple-value parameters.

If there is no value in the request then an ActionBean bound to the current form will be looked for. If the ActionBean is found and the value is non-null it will be returned. If no value can be found in either place, null will returned.

Author:
Tim Fennell

Constructor Summary
DefaultPopulationStrategy()
           
 
Method Summary
protected  Configuration getConfiguration()
          Accessor for the configuration supplied when the population strategy is initialized.
 Object getValue(InputTagSupport tag)
          Implementation of the interface method that will follow the search described in the class level JavaDoc and attempt to find a value for this tag.
protected  Object getValueFromActionBean(InputTagSupport tag)
          Helper method that will check to see if there is an ActionBean present in the request, and if so, retrieve the value for this tag from the ActionBean.
protected  Object getValueFromTag(InputTagSupport tag)
          Helper method that will retrieve the preferred value set on the tag in the JSP.
protected  String[] getValuesFromRequest(InputTagSupport tag)
          Helper method that will check the current request for user submitted values for the tag supplied and return them as a String[] if there is one or more present.
 void init(Configuration configuration)
          Called by the Configuration to configure the component.
protected  boolean isFormInError(InputTagSupport tag)
          Helper method that will check to see if the form containing this tag is being rendered as a result of validation errors.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultPopulationStrategy

public DefaultPopulationStrategy()
Method Detail

init

public void init(Configuration configuration)
          throws Exception
Called by the Configuration to configure the component.

Specified by:
init in interface ConfigurableComponent
Parameters:
configuration - the Configuration object being used by Stripes
Throws:
Exception - should be thrown if the component cannot be configured well enough to use.

getConfiguration

protected Configuration getConfiguration()
Accessor for the configuration supplied when the population strategy is initialized.


getValue

public Object getValue(InputTagSupport tag)
                throws StripesJspException
Implementation of the interface method that will follow the search described in the class level JavaDoc and attempt to find a value for this tag.

Specified by:
getValue in interface PopulationStrategy
Parameters:
tag - the form input tag whose value to populate
Returns:
Object will be one of null, a single Object or an Array of Objects depending upon what was submitted in the prior request, and what is declared on the ActionBean
Throws:
StripesJspException

getValuesFromRequest

protected String[] getValuesFromRequest(InputTagSupport tag)
                                 throws StripesJspException
Helper method that will check the current request for user submitted values for the tag supplied and return them as a String[] if there is one or more present.

Parameters:
tag - the tag whose values to look for
Returns:
a String[] if values are found, null otherwise
Throws:
StripesJspException

getValueFromActionBean

protected Object getValueFromActionBean(InputTagSupport tag)
                                 throws StripesJspException
Helper method that will check to see if there is an ActionBean present in the request, and if so, retrieve the value for this tag from the ActionBean.

Parameters:
tag - the tag whose values to look for
Returns:
an Object, possibly null, representing the tag's value
Throws:
StripesJspException

getValueFromTag

protected Object getValueFromTag(InputTagSupport tag)
Helper method that will retrieve the preferred value set on the tag in the JSP. For most tags this is usually the body if it is present, or the value attribute. In some cases tags implement this differently, notably the radio and checkbox tags.

Parameters:
tag - the tag that is being repopulated
Returns:
a value for the tag if one is specified on the JSP

isFormInError

protected boolean isFormInError(InputTagSupport tag)
                         throws StripesJspException
Helper method that will check to see if the form containing this tag is being rendered as a result of validation errors. This is not actually used by the default strategy, but is here to help subclasses provide different behaviour for when the form is rendering normally vs. in error.

Parameters:
tag - the tag that is being repopulated
Returns:
boolean true if the form is in error, false otherwise
Throws:
StripesJspException


? Copyright 2005-2006, Stripes Development Team.