Class RepopulateConversionErrorFieldValidatorSupport
- All Implemented Interfaces:
- FieldValidator,- ShortCircuitableValidator,- Validator
- Direct Known Subclasses:
- ConversionErrorFieldValidator
An abstract base class that adds in the capability to populate the stack with a fake parameter map when a conversion error has occurred and the 'repopulateField' property is set to "true".
The capability of auto-repopulating the stack with a fake parameter map when a conversion error has occurred can be done with 'repopulateField' property set to "true".
This is typically useful when one wants to repopulate the field with the original value when a conversion error occurred. Eg. with a textfield that only allows an Integer (the action class have an Integer field declared), upon conversion error, the incorrectly entered integer (maybe a text 'one') will not appear when dispatched back. With 'repopulateField' property set to true, it will, meaning the textfield will have 'one' as its value upon conversion error.
 
 <!-- myJspPage.jsp -->
 <ww:form action="someAction" method="POST">
   ....
   <ww:textfield
       label="My Integer Field"
       name="myIntegerField" />
   ....
   <ww:submit />
 </ww:form>
 
 
 
 
 <!-- xwork.xml -->
 <xwork>
 <include file="xwork-default.xml" />
 ....
 <package name="myPackage" extends="xwork-default">
   ....
   <action name="someAction" class="example.MyActionSupport.java">
      <result name="input">myJspPage.jsp</result>
      <result>success.jsp</result>
   </action>
   ....
 </package>
 ....
 </xwork>
 
 
 
 
 <!-- MyActionSupport.java -->
 public class MyActionSupport extends ActionSupport {
    private Integer myIntegerField;
    public Integer getMyIntegerField() { return this.myIntegerField; }
    public void setMyIntegerField(Integer myIntegerField) {
       this.myIntegerField = myIntegerField;
    }
 }
 
 
 
 
 <!-- MyActionSupport-someAction-validation.xml -->
 <validators>
   ...
   <field name="myIntegerField">
      <field-validator type="conversion">
         <param name="repopulateField">true</param>
         <message>Conversion Error (Integer Wanted)</message>
      </field-validator>
   </field>
   ...
 </validators>
 
 - Author:
- tm_jee
- 
Field SummaryFields inherited from class org.apache.struts2.validator.validators.FieldValidatorSupportcurrentValue, fieldName, typeFields inherited from class org.apache.struts2.validator.validators.ValidatorSupportdefaultMessage, EMPTY_STRING, messageKey, stack, textProviderFactory
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionprotected abstract voiddoValidate(Object object) protected StringbooleanvoidrepopulateField(Object object) voidsetRepopulateField(boolean repopulateField) voidThe validation implementation must guarantee that setValidatorContext will be called with a non-null ValidatorContext before validate is called.Methods inherited from class org.apache.struts2.validator.validators.FieldValidatorSupportgetCurrentValue, getFieldName, getValidatorType, setFieldName, setValidatorTypeMethods inherited from class org.apache.struts2.validator.validators.ValidatorSupportaddActionError, addFieldError, getDefaultMessage, getFieldValue, getMessage, getMessageKey, getMessageParameters, getValidatorContext, isShortCircuit, parse, setDefaultMessage, setMessageKey, setMessageParameters, setShortCircuit, setTextProviderFactory, setValidatorContext, setValueStackMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.struts2.validator.ValidatorgetDefaultMessage, getMessage, getMessageKey, getMessageParameters, getValidatorContext, setDefaultMessage, setMessageKey, setMessageParameters, setValidatorContext, setValueStack
- 
Constructor Details- 
RepopulateConversionErrorFieldValidatorSupportpublic RepopulateConversionErrorFieldValidatorSupport()
 
- 
- 
Method Details- 
isRepopulateFieldpublic boolean isRepopulateField()
- 
setRepopulateFieldpublic void setRepopulateField(boolean repopulateField) 
- 
validateDescription copied from interface:ValidatorThe validation implementation must guarantee that setValidatorContext will be called with a non-null ValidatorContext before validate is called.- Parameters:
- object- the object to be validated.
- Throws:
- ValidationException- is thrown if there is validation error(s).
 
- 
repopulateField- Throws:
- ValidationException
 
- 
escape
- 
doValidate- Throws:
- ValidationException
 
 
-