[Logo] Mentawai In Action
  [Search] Search   [Recent Topics] Recent Topics   [Hottest Topics] Hottest Topics   [Members]  Member Listing   [Groups] Back to home page 
[Moderation Log] Moderation Log   [Register] Register / 
[Login] Login 
Validation through a separate filter  XML
Forum Index » Validation
Author Message
saoj



Joined: 22/12/2007 07:20:02
Messages: 22
Offline

Instead of using the Validatable interface, which has to be implemented by the action, you can code a separate filter that will be applied to the action in the application manager. You may choose that approach if you want your action to be clean from any validation code or if you want to apply the same validation to different actions that may depend on the same form data.

To code your validation filter, you should inherit from org.mentawai.filter.ValidationFilter and implement the abstract method prepareValidator(). Check the example below:

The method prepareValidator() is very similar to the same method of the Validatable interface, the only difference being that it also passes as a parameter the action object that the filter is being applied to. The rest is the same. You can use an i18n file or you can place the error messages in the filter code, pretty much like you can do when using the Validatable interface. One thing to note is that if you use an i18n file, the name of the file will be /validation/filtername_localehere.i18n. So for the filter above it would be /validation/HelloValidator_pt.i18n, /validation/HelloValidator_en.i18n, etc.

Then you can apply the filter to one or more actions inside the application manager. Below is an example:

 
Forum Index » Validation
Go to:   
Powered by JForum 2.1.8 © JForum Team