Source code: com/sample/jsp/validation/SampleErrorHandler.java
1 /*
2 * SampleErrorHandler.java
3 *
4 * Copyright (c) 2001, 2002 Aendvari, Ltd. All Rights Reserved.
5 *
6 */
7
8 package com.sample.jsp.validation;
9
10 import com.aendvari.griffin.validation.*;
11 import com.aendvari.common.notices.*;
12
13
14 /**
15 * A sample error handler class for managing validation failures.
16 *
17 * @author Scott Milne
18 *
19 */
20
21 public class SampleErrorHandler
22 {
23 /** A {@link Notice} instance for holding all notices for later retrieval. */
24 private Notices errors;
25
26
27 /* Constructors */
28
29
30 public SampleErrorHandler()
31 {
32 errors = new Notices();
33 }
34
35 /**
36 * Adds an error to the messages list.
37 *
38 * @param propertyName The name of the property that failed validation.
39 * @param propertyValue The value of the property.
40 * @param resourceKey The resource key to use for the error message.
41 *
42 */
43
44 public void addError( String propertyName, String propertyValue, String resourceKey )
45 throws Exception
46 {
47 System.out.println("addError: [propertyName="+propertyName+"], [propertyValue="+propertyValue+"], [resourceKey="+resourceKey+"]");
48
49 Notice msg = new Notice(resourceKey, propertyName, propertyValue);
50
51 try
52 {
53 errors.addNotice( resourceKey, msg );
54 }
55 catch( Exception exception )
56 {
57 throw exception;
58 }
59 }
60
61 /**
62 * Retrieve the error messages.
63 *
64 * @return A {@link Notices} instance of all messages collected.
65 *
66 */
67
68 public Notices getErrorMessages()
69 {
70 return errors;
71 }
72 }
73