org.mentawai.filter
Class ValidationFilter

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

public class ValidationFilter
extends Object
implements Filter

Author:
Sergio Oliveira

Field Summary
static String DEFAULT_DIR
           
 
Constructor Summary
ValidationFilter()
           
 
Method Summary
 void destroy()
          Gives a chance to the filter to deallocalte any resources before it is destroyed.
 String filter(InvocationChain chain)
          Executes the filter.
static boolean isPost(Action action)
           
 void prepareValidator(Validator validator, Action action, String innerAction)
          Implement this abstract method to add rules to the fields you want to validate.
 void setDir(String dir)
          Sets the directory where to look for error messages.
 void setMessageContext(MessageContext msgContext)
          Sets the MessageContext from where you want to get the error messsages.
 void setResultForError(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

public static final String DEFAULT_DIR
See Also:
Constant Field Values
Constructor Detail

ValidationFilter

public ValidationFilter()
Method Detail

prepareValidator

public void prepareValidator(Validator validator,
                             Action action,
                             String innerAction)
Implement this abstract method to add rules to the fields you want to validate.


setResultForError

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

Parameters:
resultForError - The result to return in case of a validation failure.

setMessageContext

public void setMessageContext(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").

Parameters:
msgContext - The MessageContext to use instead of the default one.

isPost

public static boolean isPost(Action action)

setDir

public void setDir(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.

Parameters:
dir - The directory where to look for error messages.

filter

public String filter(InvocationChain chain)
              throws Exception
Description copied from interface: Filter
Executes the filter.

Specified by:
filter in interface Filter
Parameters:
chain - The InvocationChain for the action this filter is being applied to.
Returns:
The result of the filter or the action the filter is being applied to.
Throws:
Exception

destroy

public void destroy()
Description copied from interface: 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 Filter


Copyright © 2013. All Rights Reserved.