1 24 package org.riotfamily.forms; 25 26 import org.apache.commons.logging.Log; 27 import org.apache.commons.logging.LogFactory; 28 29 public class ErrorUtils { 30 31 public static final String ERROR_REQUIRED = "required"; 32 33 private static Log log = LogFactory.getLog(ErrorUtils.class); 34 35 public static void reject(Editor editor, String errorCode, Object [] args) { 36 log.debug("Rejecting value " + editor.getFieldName() + ": " + errorCode); 37 editor.getForm().getErrors().rejectValue( 38 editor.getFieldName(), errorCode, args, null); 39 40 notifyListener(editor); 41 } 42 43 public static void reject(Editor editor, String errorCode, Object arg) { 44 reject(editor, errorCode, new Object [] {arg}); 45 } 46 47 48 public static void reject(Editor editor, String errorCode) { 49 log.debug("Rejecting value " + editor.getFieldName() + ": " + errorCode); 50 editor.getForm().getErrors().rejectValue( 51 editor.getFieldName(), errorCode); 52 53 notifyListener(editor); 54 } 55 56 public static void rejectRequired(Editor editor) { 57 reject(editor, ERROR_REQUIRED); 58 } 59 60 public static void removeErrors(Element element) { 61 element.getForm().getErrors().removeErrors(element); 62 notifyListener(element); 63 } 64 65 public static boolean hasErrors(Element element) { 66 return element.getForm().getErrors().hasErrors(element); 67 } 68 69 private static void notifyListener(Element element) { 70 FormListener listener = element.getForm().getFormListener(); 71 if (listener != null) { 72 listener.elementValidated(element); 73 } 74 } 75 76 } 77 | Popular Tags |