KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jmanage > webui > validator > Validator


1 /**
2  * Copyright 2004-2005 jManage.org
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.jmanage.webui.validator;
17
18 import org.apache.struts.action.ActionErrors;
19 import org.apache.struts.action.ActionError;
20 import org.jmanage.webui.util.WebErrorCodes;
21
22 /**
23  * Date: Sep 13, 2005 5:16:29 PM
24  * @author Bhavana
25  */

26 public class Validator {
27     public static boolean validateRequired(String JavaDoc fieldValue,
28                                            String JavaDoc fieldName,
29                                            ActionErrors errors){
30         if(fieldValue==null||fieldValue.length()==0){
31             errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(
32                     WebErrorCodes.ERROR_REQUIRED, fieldName));
33             return false;
34         }
35         return true;
36     }
37     public static boolean validateInteger(String JavaDoc fieldValue,
38                                           String JavaDoc fieldName,
39                                           ActionErrors errors){
40         try {
41             Integer.parseInt(fieldValue);
42         } catch (NumberFormatException JavaDoc e) {
43             errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(
44                     WebErrorCodes.ERROR_INVALID, fieldName));
45             return false;
46         }
47         return true;
48     }
49 }
50
Popular Tags