Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.mentawai.filter
Class ValidationFilter  view ValidationFilter download ValidationFilter.java

java.lang.Object
  extended byorg.mentawai.filter.ValidationFilter
All Implemented Interfaces:
org.mentawai.core.Filter

public abstract class ValidationFilter
extends java.lang.Object
implements org.mentawai.core.Filter

A filter to validate the values of an action input. Apply this filter to validate the input values of your actions. By default, error messages are inside the /validation/ directory and a ClassMessageContext is used. (Only if LocaleManager.isUseMasterForEverything returns false) By default, the result returned when the validation fails is BaseAction.ERROR.


Field Summary
private static java.lang.String DEFAULT_DIR
           
private  java.util.Map errors
           
private  org.mentawai.message.MessageContext msgContext
           
private  java.lang.String resultForError
           
private  java.util.Map rules
           
private  Validator validator
           
 
Constructor Summary
ValidationFilter()
          Creates a ValidationFilter.
 
Method Summary
 void add(java.lang.String field, org.mentawai.rule.Rule rule, int error_id)
          Adds a validation rule to the given action input field.
 void add(java.lang.String field, org.mentawai.rule.Rule rule, java.lang.String error_id)
          Adds a validation rule to the given action input field.
 void destroy()
          Gives a chance to the filter to deallocalte any resources before it is destroyed.
 java.lang.String filter(org.mentawai.core.InvocationChain chain)
          Executes the filter.
abstract  void initValidator()
          Implement this abstract method to add rules to the fields you want to validate.
 void setDir(java.lang.String dir)
          Sets the directory where to look for error messages.
 void setMessageContext(org.mentawai.message.MessageContext msgContext)
          Sets the MessageContext from where you want to get the error messsages.
 void setResultForError(java.lang.String resultForError)
          By default, the filter returns the BaseAction.ERROR when a validation failure happens.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_DIR

private static final java.lang.String DEFAULT_DIR
See Also:
Constant Field Values

validator

private Validator validator

rules

private java.util.Map rules

errors

private java.util.Map errors

resultForError

private java.lang.String resultForError

msgContext

private org.mentawai.message.MessageContext msgContext
Constructor Detail

ValidationFilter

public ValidationFilter()
Creates a ValidationFilter. This constructor calls the initValidator() method.

Method Detail

add

public void add(java.lang.String field,
                org.mentawai.rule.Rule rule,
                int error_id)
Adds a validation rule to the given action input field. If the validation fails, show the error message specified by the given error id.


add

public void add(java.lang.String field,
                org.mentawai.rule.Rule rule,
                java.lang.String error_id)
Adds a validation rule to the given action input field. If the validation fails, show the error message specified by the given error id.

Since:
1.1.1

initValidator

public abstract void initValidator()
Implement this abstract method to add rules to the fields you want to validate.


setResultForError

public void setResultForError(java.lang.String resultForError)
By default, the filter returns the BaseAction.ERROR when a validation failure happens. You can change that by calling this method.


setMessageContext

public void setMessageContext(org.mentawai.message.MessageContext msgContext)
Sets the MessageContext from where you want to get the error messsages. You should only call this method if you want to change the default message context for this filter which is ClassMessageContext(this.getClass(), "/validation").


setDir

public void setDir(java.lang.String dir)
Sets the directory where to look for error messages. You should only call this method if you want to change the default directory, which is /validation. Note that calling this method will force the change of the message context of this filter to ClassMessageContext with the given directory.


filter

public java.lang.String filter(org.mentawai.core.InvocationChain chain)
                        throws java.lang.Exception
Description copied from interface: org.mentawai.core.Filter
Executes the filter.

Specified by:
filter in interface org.mentawai.core.Filter

destroy

public void destroy()
Description copied from interface: org.mentawai.core.Filter
Gives a chance to the filter to deallocalte any resources before it is destroyed. This is called when the web application is stopped, in other words, this has nothing to do with garbage collection.

Specified by:
destroy in interface org.mentawai.core.Filter