jp.terasoluna.fw.web.struts.reset
Class ResetterImpl

java.lang.Object
  extended by jp.terasoluna.fw.web.struts.reset.ResetterImpl
All Implemented Interfaces:
Resetter

public class ResetterImpl
extends java.lang.Object
implements Resetter

Default reset implementation class.

It is the Resetter implementation class which is provided in TERASOLUNA by default.
This class uses ResetterPlugIn and resets the form field based on the information which is set in XML file.
Since the reset() method of action form is extended, reset process is executed only in Struts lifecycle. Since the purpose of reset process is to initialize the property that contains the checkbox and radio button value, its usage for any other purpose is not assured.
*To initialize the field, change the value of model by using the business logic. In Struts lifecycle, the respective property can be rewritten again in the request parameter after performing reset.

In reset process, type cannot be identified when the value of target field is null. In case of Null, the value cannot be changed. Object type field other than null should be initialized to null value, boolean type should be initialized to false and other primitive type fields to 0. At the time of using DynaValidatorActionFormEx, please note that the field is not reset to the default value specified in struts-config.xml.
There are two reset functions, namely "Normal reset function" and "Specified range reset function" In "specified range reset function", any range can be reset for array or List object.
Any range to be reset should be stored in the request parameter by using "startIndex" and "endIndex" as key.

How to use
In form reset definition file (reset.xml), set the reset target field for each action.
  <reset>
    <action path="/resetAction">
      <property-reset name="field1" />
      <property-reset name="field2" select="true" />
    </action>
  </reset>
 
If above settings are performed and /resetAction.do is invoked, specified field of the form is cleared before reflecting the request parameter to the form.
"field1" and "field2" which are specified in the "name" attribute of property-reset tag needs to be cleared.
Since "select" attribute of "field2" is true, only the field value specified from "startIndex" ~ "endIndex" of request parameter, is initialized to null.
This class resets the nested property. To reset the nested property of action form, the combined reference format in which property name is joined with "., should be used. In the following example, nested property is reset.

Reset method of nested property
 public class MyActionForm extends ValidatorActionFormEx {
     private List rows = null;
     public void setRows(List rows) {
         this.rows = rows;
     }
     public List getRows() {
         return this.rows;
     }
     private Map map = new HashMap();
     //Omit the following
 }
 public class Row {
     private String value = null;
     public void setValue(String value) {
         this.value = value;
     }
     public String getValue() {
         return this.value;
     }
 }
 
MyActionForm class contains the list of Row class. In order to reset the value of key "field" of map property of type Map and value of property named "value" of Row class, see the following example of reset.xml.
  <reset>
    <action path="/resetAction">
      <property-reset name="rows.value" />
      <property-reset name="map(field)" />
    </action>
  </reset>
 
In multiple reference format, only property name is described. Framework automatically recognizes the array or List element and resets all the elements. Same as the normal property, reset can be performed for specified range by specifying true in select attribute.

See Also:
ResetterPlugIn, ActionReset, FieldReset, ResetterResources, FormEx, DynaValidatorActionFormEx, ValidatorActionFormEx

Field Summary
private static org.apache.commons.logging.Log log
          Log class
 
Fields inherited from interface jp.terasoluna.fw.web.struts.reset.Resetter
RESETTER_KEY
 
Constructor Summary
ResetterImpl()
           
 
Method Summary
protected  ActionReset getActionReset(org.apache.struts.action.ActionMapping mapping, javax.servlet.http.HttpServletRequest request)
          Fetches the instance of ActionReset which is linked with action path.
protected  ResetterResources getResetterResources(javax.servlet.http.HttpServletRequest request)
          Fetches the instance of ResetterResources .
 void reset(FormEx form, org.apache.struts.action.ActionMapping mapping, javax.servlet.http.HttpServletRequest request)
          Reset the field value of form.
protected  void resetSelectField(FormEx form, java.util.Map<java.lang.String,java.lang.Object> propMap, javax.servlet.http.HttpServletRequest request)
          Resets the selected field. When "true" is set in select attribute, the field value of the index which is specified from "startIndex" ~ "endIndex" of request parameter, should be initialized to null.
When the request parameter does not include "startIndex", "endIndex", all elements are reset.
When the field value type is declared as array or List type, normal reset process is performed.
protected  void resetValue(FormEx form, java.util.Map.Entry<java.lang.String,java.lang.Object> entry)
          Resets the specified property of action form. Set false when property type is boolean or Boolean type. For other primitive type and their wrapper type, set 0. When property type is the Object type other than wrapper type, set null.
Entry argument cannot be passed as null.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static org.apache.commons.logging.Log log
Log class

Constructor Detail

ResetterImpl

public ResetterImpl()
Method Detail

reset

public void reset(FormEx form,
                  org.apache.struts.action.ActionMapping mapping,
                  javax.servlet.http.HttpServletRequest request)
Resets the field value of form.

Specified by:
reset in interface Resetter
Parameters:
form - Action form
mapping - Mapping information
request - Request information
See Also:
ResetterPlugIn, ActionReset, FieldReset, ResetterResources, FormEx, DynaValidatorActionFormEx, ValidatorActionFormEx

resetValue

protected void resetValue(FormEx form,
                          java.util.Map.Entry<java.lang.String,java.lang.Object> entry)
Reset the specified property of action form. When the property type is boolean or Boolean, set false. For other primitive type and other wrapper type, set 0. When property type is the Object type other than wrapper type, set null.
Entry argument cannot be passed as null.

Parameters:
form - Action form which is used in current request
entry - Property name to be reset and entry of current value
Throws:
jp.terasoluna.fw.util.PropertyAccessException - When failed to set the property value.

getResetterResources

protected ResetterResources getResetterResources(javax.servlet.http.HttpServletRequest request)
Fetches the instance of ResetterResources.

Parameters:
request - Request information
Returns:
ResetterResources instance
See Also:
ActionReset, FieldReset

getActionReset

protected ActionReset getActionReset(org.apache.struts.action.ActionMapping mapping,
                                     javax.servlet.http.HttpServletRequest request)
Fetches instance of ActionReset which is linked with action path.

Parameters:
mapping - Mapping information of current request
request - Request information
Returns:
Instance of ActionReset
See Also:
FieldReset, ResetterResources

resetSelectField

protected void resetSelectField(FormEx form,
                                java.util.Map<java.lang.String,java.lang.Object> propMap,
                                javax.servlet.http.HttpServletRequest request)
Resets the selected fields. When true is set in the select attribute, the field value of the index which is specified from "startIndex" ~ "endIndex" of request parameter, should be initialized to null.
When the request parameter does not include "startIndex", "endIndex", reset all elements.
When the type of field value is declared as array type or List type, normal reset process is performed.

Parameters:
form - Action form which is used in current request
propMap - Map of property name and current value
request - Request information
See Also:
ActionReset, FieldReset, ResetterResources