01: package simpleorm.simplewebapp.core;
02:
03: import simpleorm.simplewebapp.core.WField;
04:
05: /**
06: * An error messageCode which will be reported to the user.
07: * Could be multiple for a given form, one per field in error.
08: */
09: public class WValidationException extends RuntimeException {
10: /** Message that will be i18ned, typicially contains {0} etc. */
11: String messageCode;
12:
13: /** The relevant pagelet, if any. Set by catchers after exception is thrown.
14: * (field may be null, but pagelets is still needed for onMaybeErroneous etc.) */
15: WPagelet pagelet;
16:
17: /** Field upon which the error occured, can be null. */
18: WField field;
19: /** Arbitrary extra parameter if needed. */
20: String parameter;
21:
22: public String getFieldName() {
23: return field == null ? null : field.getName(); // todo maybe should be fullName?
24: }
25:
26: /** Throw these to indicate user errors.
27: * Leave field null if interfield.
28: * Use setParameter if extra infor required.
29: */
30: public WValidationException(String messageCode, WField field) {
31: super (messageCode); // Just for debugging
32: this .messageCode = messageCode;
33: this .field = field;
34: }
35:
36: public @Override
37: String getLocalizedMessage() {
38: String msg = messageCode;
39: if (getField() != null)
40: msg += " Field: " + getField().getName();
41: if (getParameter() != null)
42: msg += " (" + getParameter() + ")";
43: return msg;
44: }
45:
46: ///////////// generateded ////////////////////
47:
48: public String getMessageCode() {
49: return messageCode;
50: }
51:
52: public WPagelet getPagelet() {
53: return pagelet;
54: }
55:
56: public void setPagelet(WPagelet pagelet) {
57: this .pagelet = pagelet;
58: }
59:
60: public WField getField() {
61: return field;
62: }
63:
64: public void setField(WField field) {
65: this .field = field;
66: }
67:
68: public String getParameter() {
69: return parameter;
70: }
71:
72: public WValidationException setParameter(String parameter) {
73: this.parameter = parameter;
74: return this;
75: }
76:
77: }
|