KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > riotfamily > forms > ErrorUtils


1 /* ***** BEGIN LICENSE BLOCK *****
2  * Version: MPL 1.1
3  * The contents of this file are subject to the Mozilla Public License Version
4  * 1.1 (the "License"); you may not use this file except in compliance with
5  * the License. You may obtain a copy of the License at
6  * http://www.mozilla.org/MPL/
7  *
8  * Software distributed under the License is distributed on an "AS IS" basis,
9  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
10  * for the specific language governing rights and limitations under the
11  * License.
12  *
13  * The Original Code is Riot.
14  *
15  * The Initial Developer of the Original Code is
16  * Neteye GmbH.
17  * Portions created by the Initial Developer are Copyright (C) 2006
18  * the Initial Developer. All Rights Reserved.
19  *
20  * Contributor(s):
21  * Felix Gnass [fgnass at neteye dot de]
22  *
23  * ***** END LICENSE BLOCK ***** */

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 JavaDoc ERROR_REQUIRED = "required";
32
33     private static Log log = LogFactory.getLog(ErrorUtils.class);
34
35     public static void reject(Editor editor, String JavaDoc errorCode, Object JavaDoc[] 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 JavaDoc errorCode, Object JavaDoc arg) {
44         reject(editor, errorCode, new Object JavaDoc[] {arg});
45     }
46
47
48     public static void reject(Editor editor, String JavaDoc 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