Source Code Cross Referenced for TextField.java in  » Content-Management-System » riotfamily » org » riotfamily » forms » element » 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 » Content Management System » riotfamily » org.riotfamily.forms.element 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* ***** BEGIN LICENSE BLOCK *****
002:         * Version: MPL 1.1
003:         * The contents of this file are subject to the Mozilla Public License Version
004:         * 1.1 (the "License"); you may not use this file except in compliance with
005:         * the License. You may obtain a copy of the License at
006:         * http://www.mozilla.org/MPL/
007:         * 
008:         * Software distributed under the License is distributed on an "AS IS" basis,
009:         * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
010:         * for the specific language governing rights and limitations under the
011:         * License.
012:         * 
013:         * The Original Code is Riot.
014:         * 
015:         * The Initial Developer of the Original Code is
016:         * Neteye GmbH.
017:         * Portions created by the Initial Developer are Copyright (C) 2006
018:         * the Initial Developer. All Rights Reserved.
019:         * 
020:         * Contributor(s):
021:         *   Felix Gnass [fgnass at neteye dot de]
022:         * 
023:         * ***** END LICENSE BLOCK ***** */
024:        package org.riotfamily.forms.element;
025:
026:        import java.io.PrintWriter;
027:        import java.util.regex.Pattern;
028:
029:        import org.riotfamily.common.markup.DocumentWriter;
030:        import org.riotfamily.common.markup.Html;
031:        import org.riotfamily.forms.ErrorUtils;
032:        import org.riotfamily.forms.MessageUtils;
033:        import org.riotfamily.forms.request.FormRequest;
034:        import org.springframework.util.ObjectUtils;
035:        import org.springframework.util.StringUtils;
036:
037:        /**
038:         * A text input field.
039:         */
040:        public class TextField extends AbstractTextElement {
041:
042:            private static final String CONFIRM_SUFFIX = "-confirm";
043:
044:            private static final String DEFAULT_CONFIRM_MESSAGE_KEY = "label.textField.confirmInput";
045:
046:            private static final String DEFAULT_REGEX_MISMATCH_MESSAGE_KEY = "error.textField.regexMismatch";
047:
048:            private boolean confirm;
049:
050:            private String confirmText = null;
051:
052:            private String confirmMessageKey;
053:
054:            private String confirmMessageText;
055:
056:            private Pattern pattern;
057:
058:            private String regexMismatchMessageKey = DEFAULT_REGEX_MISMATCH_MESSAGE_KEY;
059:
060:            private String regexMismatchMessageText;
061:
062:            public TextField() {
063:                this ("text");
064:            }
065:
066:            public TextField(String s) {
067:                super (s);
068:            }
069:
070:            public void setConfirm(boolean confirm) {
071:                this .confirm = confirm;
072:            }
073:
074:            public void setConfirmMessageKey(String confirmMessageKey) {
075:                this .confirmMessageKey = confirmMessageKey;
076:            }
077:
078:            public void setConfirmMessageText(String confirmMessageText) {
079:                this .confirmMessageText = confirmMessageText;
080:            }
081:
082:            public void setRegex(String regex) {
083:                this .pattern = Pattern.compile(regex);
084:                setValidateOnChange(true);
085:            }
086:
087:            public void setRegexMismatchMessageKey(
088:                    String regexMismatchMessageKey) {
089:                this .regexMismatchMessageKey = regexMismatchMessageKey;
090:            }
091:
092:            public void setRegexMismatchMessageText(
093:                    String regexMismatchMessageText) {
094:                this .regexMismatchMessageText = regexMismatchMessageText;
095:            }
096:
097:            public void renderInternal(PrintWriter writer) {
098:                if (confirm) {
099:                    DocumentWriter doc = new DocumentWriter(writer);
100:                    doc.start(Html.DIV).attribute(Html.COMMON_CLASS,
101:                            "confirm-text");
102:                    doc.body();
103:                    super .renderInternal(writer);
104:                    String msg = MessageUtils.getMessage(this ,
105:                            getConfirmMessage());
106:                    doc.start(Html.P).body(msg).end();
107:
108:                    doc.startEmpty(Html.INPUT).attribute(Html.INPUT_TYPE,
109:                            getType()).attribute(Html.COMMON_CLASS,
110:                            getStyleClass()).attribute(Html.INPUT_NAME,
111:                            getConfirmParamName()).attribute(Html.INPUT_VALUE,
112:                            confirmText != null ? confirmText : getText());
113:
114:                    doc.closeAll();
115:                } else {
116:                    super .renderInternal(writer);
117:                }
118:            }
119:
120:            public void processRequest(FormRequest request) {
121:                if (confirm) {
122:                    confirmText = request.getParameter(getConfirmParamName());
123:                }
124:                super .processRequest(request);
125:            }
126:
127:            public void validate() {
128:                super .validate();
129:                if (confirm) {
130:                    if (!ObjectUtils.nullSafeEquals(getText(), confirmText)) {
131:                        ErrorUtils.reject(this ,
132:                                "error.textField.confirmationFailed");
133:                    }
134:                }
135:            }
136:
137:            protected void validateSyntax() {
138:                if (pattern != null && StringUtils.hasLength(getText())) {
139:                    if (!pattern.matcher(getText()).matches()) {
140:                        getForm().getErrors().rejectValue(getFieldName(),
141:                                regexMismatchMessageKey,
142:                                regexMismatchMessageText);
143:                    }
144:                }
145:            }
146:
147:            protected String getConfirmParamName() {
148:                return getParamName() + CONFIRM_SUFFIX;
149:            }
150:
151:            protected String getConfirmMessage() {
152:                if (confirmMessageText != null) {
153:                    return confirmMessageText;
154:                } else if (confirmMessageKey != null) {
155:                    return MessageUtils.getMessage(this , confirmMessageKey);
156:                } else {
157:                    return MessageUtils.getMessage(this ,
158:                            getDefaultConfirmMessageKey());
159:                }
160:            }
161:
162:            protected String getDefaultConfirmMessageKey() {
163:                return DEFAULT_CONFIRM_MESSAGE_KEY;
164:            }
165:
166:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.