Source Code Cross Referenced for AbstractFormValidator.java in  » J2EE » wicket » org » apache » wicket » markup » html » form » validation » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » wicket » org.apache.wicket.markup.html.form.validation 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.apache.wicket.markup.html.form.validation;
018:
019:        import java.util.HashMap;
020:        import java.util.Map;
021:
022:        import org.apache.wicket.markup.html.form.FormComponent;
023:        import org.apache.wicket.model.IModel;
024:        import org.apache.wicket.util.lang.Classes;
025:        import org.apache.wicket.validation.IValidatable;
026:        import org.apache.wicket.validation.IValidationError;
027:        import org.apache.wicket.validation.ValidationError;
028:
029:        /**
030:         * Base class for {@link org.apache.wicket.markup.html.form.validation.IFormValidator}s.
031:         * 
032:         * @author Igor Vaynberg (ivaynberg)
033:         */
034:        public abstract class AbstractFormValidator implements  IFormValidator {
035:            /**
036:             * DEPRECATED/UNSUPPORTED
037:             * 
038:             * Gets the default variables for interpolation.
039:             * 
040:             * @return a map with the variables for interpolation
041:             * 
042:             * @deprecated use {@link #variablesMap(IValidatable)} instead
043:             * @throws UnsupportedOperationException
044:             * 
045:             * FIXME 2.0: remove asap
046:             */
047:            protected final Map messageModel() {
048:                throw new UnsupportedOperationException(
049:                        "THIS METHOD IS DEPRECATED, SEE JAVADOC");
050:            }
051:
052:            /**
053:             * Reports an error against validatable using the map returned by
054:             * {@link #variablesMap(IValidatable)}for variable interpolations and
055:             * message key returned by {@link #resourceKey()}.
056:             * 
057:             * @param fc
058:             *            form component against which the error is reported
059:             * 
060:             */
061:            public void error(FormComponent fc) {
062:                error(fc, resourceKey(), variablesMap());
063:            }
064:
065:            /**
066:             * Reports an error against the validatalbe using the given resource key
067:             * 
068:             * @param fc
069:             *            form component against which the error is reported
070:             * @param resourceKey
071:             *            The message resource key to use
072:             */
073:            public void error(FormComponent fc, final String resourceKey) {
074:                if (resourceKey == null) {
075:                    throw new IllegalArgumentException(
076:                            "Argument [[resourceKey]] cannot be null");
077:                }
078:                error(fc, resourceKey, variablesMap());
079:            }
080:
081:            /**
082:             * Reports an error against the validatalbe using the given map for variable
083:             * interpolations and message resource key provided by
084:             * {@link #resourceKey()}
085:             * 
086:             * @param fc
087:             *            form component against which the error is reported
088:             * @param vars
089:             *            variables for variable interpolation
090:             */
091:            public void error(FormComponent fc, final Map vars) {
092:                if (vars == null) {
093:                    throw new IllegalArgumentException(
094:                            "Argument [[vars]] cannot be null");
095:                }
096:                error(fc, resourceKey(), vars);
097:            }
098:
099:            /**
100:             * Reports an error against the validatable using the specified resource key
101:             * and variable map
102:             * 
103:             * @param fc
104:             *            form component against which the error is reported
105:             * 
106:             * @param validatable
107:             *            validatble being validated
108:             * @param resourceKey
109:             *            The message resource key to use
110:             * @param vars
111:             *            The model for variable interpolation
112:             */
113:            public void error(FormComponent fc, final String resourceKey,
114:                    Map vars) {
115:                if (fc == null) {
116:                    throw new IllegalArgumentException(
117:                            "Argument [[fc]] cannot be null");
118:                }
119:                if (vars == null) {
120:                    throw new IllegalArgumentException(
121:                            "Argument [[vars]] cannot be null");
122:                }
123:                if (resourceKey == null) {
124:                    throw new IllegalArgumentException(
125:                            "Argument [[resourceKey]] cannot be null");
126:                }
127:
128:                ValidationError error = new ValidationError()
129:                        .addMessageKey(resourceKey);
130:                final String defaultKey = Classes.simpleName(getClass());
131:                if (!resourceKey.equals(defaultKey)) {
132:                    error.addMessageKey(defaultKey);
133:                }
134:
135:                error.setVariables(vars);
136:                fc.error((IValidationError) error);
137:            }
138:
139:            /**
140:             * Gets the default variables for interpolation. These are for every
141:             * component:
142:             * <ul>
143:             * <li>${input(n)}: the user's input</li>
144:             * <li>${name(n)}: the name of the component</li>
145:             * <li>${label(n)}: the label of the component - either comes from
146:             * FormComponent.labelModel or resource key [form-id].[form-component-id] in
147:             * that order</li>
148:             * </ul>
149:             * 
150:             * @return a map with the variables for interpolation
151:             */
152:            protected Map variablesMap() {
153:                FormComponent[] formComponents = getDependentFormComponents();
154:
155:                if (formComponents != null && formComponents.length > 0) {
156:                    Map args = new HashMap(formComponents.length * 3);
157:                    for (int i = 0; i < formComponents.length; i++) {
158:                        final FormComponent formComponent = formComponents[i];
159:
160:                        String arg = "label" + i;
161:                        IModel label = formComponent.getLabel();
162:                        if (label != null) {
163:                            args.put(arg, label.getObject());
164:                        } else {
165:                            args.put(arg, formComponent.getLocalizer()
166:                                    .getString(formComponent.getId(),
167:                                            formComponent.getParent(),
168:                                            formComponent.getId()));
169:                        }
170:
171:                        args.put("input" + i, formComponent.getInput());
172:                        args.put("name" + i, formComponent.getId());
173:                    }
174:                    return args;
175:                } else {
176:                    return new HashMap(2);
177:                }
178:            }
179:
180:            /**
181:             * Gets the resource key for validator's error message from the
182:             * ApplicationSettings class.
183:             * 
184:             * @return the resource key based on the form component
185:             */
186:            protected String resourceKey() {
187:                return Classes.simpleName(getClass());
188:            }
189:        }
w___w__w__.___j__a___v_a_2__s__._c___o___m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.