Source Code Cross Referenced for HtmlSSNSingleComponent.java in  » J2EE » Sofia » com » salmonllc » html » 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 » Sofia » com.salmonllc.html 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.salmonllc.html;
002:
003:        /////////////////////////
004:        //$Archive: /SOFIA/SourceCode/com/salmonllc/html/HtmlSSNSingleComponent.java $
005:        //$Author: Dan $ 
006:        //$Revision: 11 $ 
007:        //$Modtime: 10/20/03 3:30p $ 
008:        /////////////////////////
009:        import java.util.Hashtable;
010:
011:        import com.salmonllc.html.events.ValueChangedEvent;
012:        import com.salmonllc.util.Util;
013:
014:        /**
015:         * 	This class creates a component for the editing of a social security number as a single edit field.
016:         */
017:
018:        public class HtmlSSNSingleComponent extends HtmlFormComponent {
019:            private HtmlTextEdit _editSSN;
020:            private char _fSeparator = '-';
021:            private static String _separatorStr = "-";
022:
023:            /**
024:             * 	This is the constructor of this class, and initializes the SSN Component.
025:             *	@param name	java.lang.String Name of component.
026:             * 	@param p HtmlPage Page containing component.
027:             */
028:            public HtmlSSNSingleComponent(String name, HtmlPage p) {
029:                super (name, p);
030:                _editSSN = new HtmlTextEdit(name, p);
031:                _editSSN.setGenerateNewline(false);
032:                _editSSN.setSize(11);
033:                _editSSN.setMaxLength(11);
034:            }
035:
036:            /**
037:             *	This method returns the SSN of a user with proper format (i.e. with dashes).
038:             *	@param s java.lang.String A string of the SSN value to be formatted.
039:             * 	@return java.lang.String
040:             */
041:
042:            public static String formatValue(String s) {
043:                String ssn;
044:
045:                if (s == null) {
046:                    ssn = "";
047:                } else if (s.length() == 9) {
048:                    ssn = s.substring(0, 3) + _separatorStr + s.substring(3, 5)
049:                            + _separatorStr + s.substring(5);
050:                } else {
051:                    ssn = s;
052:                }
053:                return ssn;
054:            }
055:
056:            /**
057:             * 	This method generates the part of the HTML for the page used to render the SSN component.
058:             * 	@param p java.io.PrintWriter
059:             * 	@param row int
060:             */
061:
062:            public void generateHTML(java.io.PrintWriter p, int row)
063:                    throws Exception {
064:                // It is essential to call getValue() here because there may be a ValueChanged
065:                // event in the queue for this object, which needs to be removed, which getValue()
066:                // does.  The secondary calls to getValue() from the container will not
067:                // do this because there are no events associated with them.
068:                String val = getValue(row, true);
069:                if (val == null) {
070:                    _editSSN.setValue(null, row);
071:                } else {
072:                    String sVal;
073:                    if (_dsBuff != null) {
074:                        if (row >= 0)
075:                            sVal = _dsBuff.getString(row, _dsColNo);
076:                        else
077:                            sVal = _dsBuff.getString(_dsColNo);
078:                    } else {
079:                        sVal = val;
080:                    }
081:                    _editSSN.setValue(formatValue(sVal), row);
082:                }
083:                _editSSN.generateHTML(p, row);
084:                if (_visible && _enabled)
085:                    p.println("");
086:            }
087:
088:            /**
089:             * 	This method returns the sub-component to be used for setting focus.
090:             * 	@return com.salmonllc.html.HtmlComponent
091:             */
092:            public HtmlComponent getFocus() {
093:                return _editSSN;
094:            }
095:
096:            /**
097:             *	This method returns the SSN of a user with proper format (i.e. with dashes).
098:             * 	@return java.lang.String
099:             */
100:
101:            public String getFormattedValue() {
102:                return formatValue(super .getValue());
103:            }
104:
105:            /**
106:             * This method returns the seperator character for the social security number.
107:             */
108:            public String getSeparator() {
109:                return new Character(_fSeparator).toString();
110:            }
111:
112:            /**
113:             *	This method gets the value of the SSN# and returns it in a string format.
114:             * 	@return java.lang.String
115:             */
116:
117:            public String getValue() {
118:                return Util.stripChars(super .getValue(), "0123456789", null);
119:            }
120:
121:            /**	
122:             *	This method checks to see if the user-entered value for the SSN# is valid.
123:             *	@return boolean if the SSN# is valid.
124:             */
125:
126:            public boolean isValid() {
127:                String s = getValue();
128:                if (s == null) {
129:                    return false;
130:                } else if (s.length() == 9) {
131:                    return Util.isNumeric(s);
132:                } else if (s.length() == 11) {
133:                    if ((s.charAt(3) != _fSeparator)
134:                            || (s.charAt(6) != _fSeparator)
135:                            || !Util.isNumeric(s.substring(0, 3))
136:                            || !Util.isNumeric(s.substring(4, 6))
137:                            || !Util.isNumeric(s.substring(7, 11))) {
138:                        return false;
139:                    } else {
140:                        setValue(s.substring(0, 3) + s.substring(4, 6)
141:                                + s.substring(7, 11));
142:                        return true;
143:                    }
144:                } else {
145:                    return false;
146:                }
147:            }
148:
149:            /**
150:             *	This method compares the contents of the SSN component with that in the corresponding row and column in the datastore to determine if a change has occurred.
151:             *	@param parms Hashtable
152:             *	@param rowNo int
153:             *	@return boolean 
154:             */
155:
156:            public boolean processParms(Hashtable parms, int rowNo)
157:                    throws Exception {
158:
159:                if (!getVisible() || !getEnabled())
160:                    return false;
161:
162:                String oldValue;
163:                if (_dsBuff == null) {
164:                    oldValue = _editSSN.getValue();
165:                } else {
166:                    String s;
167:                    if (rowNo > -1)
168:                        s = _dsBuff.getString(rowNo, _dsColNo);
169:                    else
170:                        s = _dsBuff.getString(_dsColNo);
171:                    if (s == null)
172:                        oldValue = null;
173:                    else
174:                        oldValue = s;
175:                }
176:
177:                String newValue;
178:                String name1 = _editSSN.getFullName();
179:                if (rowNo > -1)
180:                    name1 += "_" + rowNo;
181:                String val[] = (String[]) parms.get(name1);
182:                if (val != null) {
183:                    newValue = val[0].trim();
184:                    if (newValue.equals(""))
185:                        newValue = null;
186:                    else if (newValue.length() == 11)
187:                        newValue = newValue.substring(0, 3)
188:                                + newValue.substring(4, 6)
189:                                + newValue.substring(7, 11);
190:                } else {
191:                    newValue = null;
192:                }
193:
194:                // Compare old and new values and possibly create a ValueChangedEvent.
195:                if (!valuesEqual(oldValue, newValue)) {
196:                    ValueChangedEvent e = new ValueChangedEvent(getPage(),
197:                            this , getName(), getFullName(), oldValue, newValue,
198:                            rowNo, _dsColNo, _dsBuff);
199:                    addEvent(e);
200:                }
201:                return false;
202:            }
203:
204:            /**
205:             * 	This method will clear all pending events from the event queue for this component. 
206:             */
207:            public void reset() {
208:                super .reset();
209:                _editSSN.reset();
210:            }
211:
212:            /**
213:             *	This method is used to associate a specific set of properties from the properties file with the SSN component to change its presentation from the default one.
214:             *	@param theme java.lang.String
215:             */
216:
217:            public void setClassName(String sClass) {
218:                super .setClassName(sClass);
219:                if (sClass != null)
220:                    _editSSN.setClassName(sClass);
221:            }
222:
223:            /**
224:             * Sets the font end tag for disabled mode.
225:             * @param tag java.lang.String
226:             */
227:            public void setDisabledFontEndTag(String tag) {
228:                _editSSN.setDisabledFontEndTag(tag);
229:
230:            }
231:
232:            /**
233:             * Sets the font tag for disabled mode.
234:             * @param tag java.lang.String
235:             */
236:            public void setDisabledFontStartTag(String tag) {
237:
238:                _editSSN.setDisabledFontStartTag(tag);
239:
240:            }
241:
242:            /**
243:             * 	This method enables or disables the ability of this component to respond to user input.
244:             * 	@param editable boolean
245:             */
246:            public void setEnabled(boolean enabled) {
247:                super .setEnabled(enabled);
248:                _editSSN.setEnabled(enabled);
249:            }
250:
251:            /**
252:             *	This method sets the parent of the SSN component, i.e. the component containing the SSN component, so that the component can be named properly.  
253:             *	@param parent HtmlComponent 
254:             */
255:
256:            public void setParent(HtmlComponent parent) {
257:                super .setParent(parent);
258:                // This is necessary for the name to be generated correctly, else the leading
259:                // sequence of parent names will be lost.
260:                _editSSN.setParent(parent);
261:
262:            }
263:
264:            /**
265:             * This method sets the seperator character for the ssn
266:             */
267:            public void setSeparator(String newSeparator) {
268:                _fSeparator = newSeparator.charAt(0);
269:                _separatorStr = newSeparator;
270:            }
271:
272:            /**
273:             *	This method is used to associate a specific set of properties from the properties file with the SSN component to change its presentation from the default one.
274:             *	@param theme java.lang.String
275:             */
276:
277:            public void setTheme(String theme) {
278:                super .setTheme(theme);
279:                if (theme != null)
280:                    _editSSN.setTheme(theme);
281:            }
282:
283:            /**
284:             * @returns the access key html attribute
285:             */
286:            public String getAccessKey() {
287:                return _editSSN.getAccessKey();
288:            }
289:
290:            /**
291:             * @returns the read only html attribute
292:             */
293:            public boolean getReadOnly() {
294:                return _editSSN.getReadOnly();
295:            }
296:
297:            /**
298:             * @returns the tab index html attribute
299:             */
300:            public int getTabIndex() {
301:                return _editSSN.getTabIndex();
302:            }
303:
304:            /**
305:             * @param sets the access key html attribute
306:             */
307:            public void setAccessKey(String val) {
308:                _editSSN.setAccessKey(val);
309:            }
310:
311:            /**
312:             * @param sets the read only html attribute
313:             */
314:            public void setReadOnly(boolean val) {
315:                _editSSN.setReadOnly(val);
316:            }
317:
318:            /**
319:             * @param sets the tab index html attribute. You can also pass TAB_INDEX_DEFAULT to use the default tab index for the component or TAB_INDEX_NONE to keep this component from being tabbed to
320:             */
321:            public void setTabIndex(int val) {
322:                _editSSN.setTabIndex(val);
323:            }
324:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.