KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > quikj > application > communicator > applications > webtalk > controller > ValidatorUtil


1 /*
2  * ValidatorUtil.java
3  *
4  * Created on March 20, 2004, 3:13 PM
5  *
6  * This class contains generic validator methods to make up for current Struts release validator bugs/deficiences.
7  *
8  */

9
10 package com.quikj.application.communicator.applications.webtalk.controller;
11
12 import javax.servlet.http.*;
13 import org.apache.struts.action.*;
14 import org.apache.struts.validator.*;
15 import org.apache.commons.validator.*;
16
17 /**
18  *
19  * @author bhm
20  */

21 public class ValidatorUtil
22 {
23     
24     /** Creates a new instance of ValidatorUtil */
25     public ValidatorUtil()
26     {
27     }
28     
29     public static boolean validateStringRequiredIf( // not needed starting Struts 1.2 (requiredif will be fixed and also validwhen is available)
30
Object JavaDoc bean,
31     ValidatorAction va,
32     Field field,
33     ActionErrors errors,
34     HttpServletRequest request)
35     {
36         DynaValidatorForm form = (DynaValidatorForm)bean;
37         
38         // Get the submit value that requires this field to be there
39
String JavaDoc required_if = field.getVarValue("submit");
40         
41         // See if the form submit equals that
42
if (((String JavaDoc)form.get("submit")).equals(required_if) == true)
43         {
44             // Get the data in the field being checked
45
String JavaDoc value = (String JavaDoc)form.get(field.getProperty());
46             
47             if (value == null)
48             {
49                 errors.add(field.getKey(), Resources.getActionError(request, va, field));
50                 return false;
51             }
52             
53             if (value.trim().length() <= 0)
54             {
55                 errors.add(field.getKey(), Resources.getActionError(request, va, field));
56                 return false;
57             }
58         }
59         
60         return true;
61     }
62     
63 }
64
Popular Tags