Package org.jmanage.webui.validator

Source Code of org.jmanage.webui.validator.Validator

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

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionError;
import org.jmanage.webui.util.WebErrorCodes;

/**
* Date: Sep 13, 2005 5:16:29 PM
* @author Bhavana
*/
public class Validator {
    public static boolean validateRequired(String fieldValue,
                                           String fieldName,
                                           ActionErrors errors){
        if(fieldValue==null||fieldValue.length()==0){
            errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(
                    WebErrorCodes.ERROR_REQUIRED, fieldName));
            return false;
        }
        return true;
    }
    public static boolean validateInteger(String fieldValue,
                                          String fieldName,
                                          ActionErrors errors){
        try {
            Integer.parseInt(fieldValue);
        } catch (NumberFormatException e) {
            errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(
                    WebErrorCodes.ERROR_INVALID, fieldName));
            return false;
        }
        return true;
    }
}
TOP

Related Classes of org.jmanage.webui.validator.Validator

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.