1 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 26 public class Validator { 27 public static boolean validateRequired(String fieldValue, 28 String 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 fieldValue, 38 String fieldName, 39 ActionErrors errors){ 40 try { 41 Integer.parseInt(fieldValue); 42 } catch (NumberFormatException 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 |