Source Code Cross Referenced for FieldLabelTag.java in  » Web-Framework » Strecks » org » strecks » web » tag » 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 » Web Framework » Strecks » org.strecks.web.tag 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2005-2006 the original author or authors.
003:         * 
004:         * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
005:         * in compliance with the License. You may obtain a copy of the License at
006:         * 
007:         * http://www.apache.org/licenses/LICENSE-2.0
008:         * 
009:         * Unless requiredSuffix by applicable law or agreed to in writing, software distributed under the License
010:         * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
011:         * or implied. See the License for the specific language governing permissions and limitations under
012:         * the License.
013:         */
014:
015:        package org.strecks.web.tag;
016:
017:        import java.util.Iterator;
018:
019:        import javax.servlet.jsp.JspException;
020:        import javax.servlet.jsp.tagext.TagSupport;
021:
022:        import org.apache.struts.Globals;
023:        import org.apache.struts.action.ActionMessages;
024:        import org.apache.struts.taglib.TagUtils;
025:
026:        /**
027:         * Tags which shows which fields are in error. Allows error styles to be added to the field label in
028:         * the event of an error in form submission. Also allows for localized field labels.
029:         * 
030:         * @author Phil Zoio
031:         */
032:        public class FieldLabelTag extends TagSupport {
033:
034:            private static final long serialVersionUID = -2706602151601105905L;
035:
036:            /**
037:             * The name of the property for which error messages should be returned
038:             */
039:            protected String property = null;
040:
041:            /**
042:             * The message resource key for errors prefix.
043:             */
044:            protected String errorPrefix = null;
045:
046:            /**
047:             * The message resource key for errors suffix.
048:             */
049:            protected String errorSuffix = null;
050:
051:            /**
052:             * The label for the field
053:             */
054:            protected String label = null;
055:
056:            /**
057:             * The label for the field
058:             */
059:            protected String labelKey = null;
060:
061:            /**
062:             * Whether the field is requiredSuffix
063:             */
064:            protected boolean required = false;
065:
066:            /**
067:             * The label for the field
068:             */
069:            protected String requiredPrefix = null;
070:
071:            /**
072:             * The label for the field
073:             */
074:            protected String requiredSuffix = null;
075:
076:            // ------------------------------------------------------- Public Methods
077:
078:            /**
079:             * Render the specified error messages if there are any.
080:             * 
081:             * @exception JspException
082:             *                if a JSP exception has occurred
083:             */
084:            public int doStartTag() throws JspException {
085:
086:                String toWrite = getResultString();
087:                TagUtils.getInstance().write(pageContext, toWrite);
088:                return (EVAL_BODY_INCLUDE);
089:
090:            }
091:
092:            String getResultString() throws JspException {
093:
094:                // Were any error messages specified?
095:                ActionMessages errors = null;
096:                try {
097:                    errors = TagUtils.getInstance().getActionMessages(
098:                            pageContext, Globals.ERROR_KEY);
099:                } catch (JspException e) {
100:                    TagUtils.getInstance().saveException(pageContext, e);
101:                    throw e;
102:                }
103:
104:                boolean errorPrefixPresent = TagUtils.getInstance().present(
105:                        pageContext, null, null, getErrorPrefix());
106:
107:                boolean errorSuffixPresent = TagUtils.getInstance().present(
108:                        pageContext, null, null, getErrorSuffix());
109:
110:                boolean requiredPrefixPresent = TagUtils.getInstance().present(
111:                        pageContext, null, null, getRequiredPrefix());
112:
113:                boolean requiredSuffixPresent = TagUtils.getInstance().present(
114:                        pageContext, null, null, getRequiredSuffix());
115:
116:                // Render the error messages appropriately
117:                StringBuffer results = new StringBuffer();
118:
119:                Iterator reports = errors.get(property);
120:
121:                if (reports != null && reports.hasNext()) {
122:
123:                    String message = null;
124:                    if (errorPrefixPresent) {
125:                        message = TagUtils.getInstance().message(pageContext,
126:                                Globals.MESSAGES_KEY, Globals.LOCALE_KEY,
127:                                getErrorPrefix());
128:                        results.append(message);
129:                    }
130:
131:                    if (required && requiredPrefixPresent) {
132:                        message = TagUtils.getInstance().message(pageContext,
133:                                Globals.MESSAGES_KEY, Globals.LOCALE_KEY,
134:                                getRequiredPrefix());
135:                        results.append(message);
136:                    }
137:
138:                    addLabel(results);
139:
140:                    if (required && requiredSuffixPresent) {
141:                        message = TagUtils.getInstance().message(pageContext,
142:                                Globals.MESSAGES_KEY, Globals.LOCALE_KEY,
143:                                getRequiredSuffix());
144:                        results.append(message);
145:                    }
146:
147:                    if (errorSuffixPresent) {
148:                        message = TagUtils.getInstance().message(pageContext,
149:                                Globals.MESSAGES_KEY, Globals.LOCALE_KEY,
150:                                getErrorSuffix());
151:                        results.append(message);
152:                    }
153:                } else {
154:                    if (required && requiredPrefixPresent) {
155:                        String message = TagUtils.getInstance().message(
156:                                pageContext, Globals.MESSAGES_KEY,
157:                                Globals.LOCALE_KEY, getRequiredPrefix());
158:                        results.append(message);
159:                    }
160:
161:                    addLabel(results);
162:
163:                    if (required && requiredSuffixPresent) {
164:                        String message = TagUtils.getInstance().message(
165:                                pageContext, Globals.MESSAGES_KEY,
166:                                Globals.LOCALE_KEY, getRequiredSuffix());
167:                        results.append(message);
168:                    }
169:                }
170:
171:                String toWrite = results.toString();
172:                return toWrite;
173:            }
174:
175:            private void addLabel(StringBuffer results) throws JspException {
176:                String message;
177:                if (getLabelKey() != null) {
178:                    message = TagUtils.getInstance().message(pageContext,
179:                            Globals.MESSAGES_KEY, Globals.LOCALE_KEY,
180:                            getLabelKey());
181:                    results.append(message);
182:                } else if (getLabel() != null) {
183:                    results.append(getLabel());
184:                } else {
185:                    throw new JspException(
186:                            "FieldLabel tag must specify a non-null 'label' or 'labelKey' property");
187:                }
188:            }
189:
190:            /**
191:             * Release any acquired resources.
192:             */
193:            public void release() {
194:                super .release();
195:                property = null;
196:                label = null;
197:                labelKey = null;
198:                errorPrefix = null;
199:                errorSuffix = null;
200:                required = false;
201:                requiredPrefix = null;
202:                requiredSuffix = null;
203:            }
204:
205:            /* ****** getters and setters ******* */
206:
207:            public void setProperty(String property) {
208:                this .property = property;
209:            }
210:
211:            public String getErrorPrefix() {
212:                return errorPrefix == null ? "field.error.prefix" : errorPrefix;
213:            }
214:
215:            public void setErrorPrefix(String prefix) {
216:                this .errorPrefix = prefix;
217:            }
218:
219:            public String getErrorSuffix() {
220:                return errorSuffix == null ? "field.error.suffix" : errorSuffix;
221:            }
222:
223:            public void setErrorSuffix(String suffix) {
224:                this .errorSuffix = suffix;
225:            }
226:
227:            public void setLabel(String label) {
228:                this .label = label;
229:            }
230:
231:            public String getLabel() {
232:                return label;
233:            }
234:
235:            public String getProperty() {
236:                return property;
237:            }
238:
239:            public String getLabelKey() {
240:                return labelKey;
241:            }
242:
243:            public void setLabelKey(String labelKey) {
244:                this .labelKey = labelKey;
245:            }
246:
247:            public boolean isRequired() {
248:                return required;
249:            }
250:
251:            public void setRequired(boolean mandatory) {
252:                this .required = mandatory;
253:            }
254:
255:            public String getRequiredSuffix() {
256:                return requiredSuffix == null ? "field.required.suffix"
257:                        : requiredSuffix;
258:            }
259:
260:            public String getRequiredPrefix() {
261:                return requiredPrefix == null ? "field.required.prefix"
262:                        : requiredPrefix;
263:            }
264:
265:            public void setRequiredSuffix(String required) {
266:                this .requiredSuffix = required;
267:            }
268:
269:            public void setRequiredPrefix(String requiredPrefix) {
270:                this.requiredPrefix = requiredPrefix;
271:            }
272:
273:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.