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


001:        package com.salmonllc.jsp.tags;
002:
003:        /////////////////////////
004:        //$Archive: /SOFIA/SourceCode/com/salmonllc/jsp/tags/ValidatorTag.java $
005:        //$Author: Fred $
006:        //$Revision: 28 $
007:        //$Modtime: 6/10/04 11:43a $
008:        /////////////////////////
009:
010:        import java.lang.reflect.Constructor;
011:        import java.util.StringTokenizer;
012:        import java.util.Vector;
013:
014:        import javax.servlet.jsp.JspException;
015:        import javax.servlet.jsp.JspWriter;
016:
017:        import com.salmonllc.html.HtmlComponent;
018:        import com.salmonllc.html.HtmlFormComponent;
019:        import com.salmonllc.html.HtmlLookUpComponent;
020:        import com.salmonllc.html.HtmlPage;
021:        import com.salmonllc.html.HtmlSubmitButton;
022:        import com.salmonllc.html.HtmlSubmitImage;
023:        import com.salmonllc.html.HtmlValidatorText;
024:        import com.salmonllc.jsp.JspController;
025:        import com.salmonllc.jsp.JspLink;
026:        import com.salmonllc.sql.DataStoreBuffer;
027:        import com.salmonllc.sql.DataStoreException;
028:        import com.salmonllc.util.MessageLog;
029:
030:        /**
031:         * This class creates a validator tag
032:         */
033:        public class ValidatorTag extends BaseBodyTag {
034:
035:            public class Attributes {
036:                public String name;
037:                public String font;
038:                public String dbprofile;
039:                public String validatenewrows;
040:                public String autopopulatelookups;
041:                public String breaksbefore;
042:                public String breaksafter;
043:                public String breaksbetween;
044:                public String fixhtml;
045:                public String allowmultipleerrors;
046:                public String validatorClass;
047:                public String useJavaScriptForRules;
048:                public String useJavaScriptForRangeRules;
049:                public String useJavaScriptForRegExpRules;
050:                public String useJavaScriptForRequiredRules;
051:                public String useJavaScriptForValidationsOnly;
052:                public String useAlertsForErrors;
053:                public String addFocusLinksToErrors;
054:                public String autoImportRules;
055:
056:                public String datasource;
057:                public String submitcomponents;
058:                public Vector expRules;
059:                public Vector lookupRules;
060:                public Vector typeCheckRules;
061:                public Vector regExpRules;
062:                public Vector javascriptRules;
063:                public Vector requiredRules;
064:                public Vector rangeRules;
065:            }
066:
067:            private Attributes _att = new Attributes();
068:
069:            public int doStartTag() throws JspException {
070:                return super .doStartTag();
071:
072:            }
073:
074:            void addExpressionRule(ValidatorRuleTag.Attributes a) {
075:                if (_att.expRules == null)
076:                    _att.expRules = new Vector();
077:                _att.expRules.addElement(a);
078:            }
079:
080:            void addRangeRule(ValidatorRangeTag.Attributes a) {
081:                if (_att.rangeRules == null)
082:                    _att.rangeRules = new Vector();
083:                _att.rangeRules.addElement(a);
084:            }
085:
086:            void addLookupRule(ValidatorLookupTag.Attributes a) {
087:                if (_att.lookupRules == null)
088:                    _att.lookupRules = new Vector();
089:                _att.lookupRules.addElement(a);
090:            }
091:
092:            void addTypeCheckRule(ValidatorTypeCheckTag.Attributes a) {
093:                if (_att.typeCheckRules == null)
094:                    _att.typeCheckRules = new Vector();
095:                _att.typeCheckRules.addElement(a);
096:            }
097:
098:            void addRegExpRule(ValidatorRegExpTag.Attributes a) {
099:                if (_att.regExpRules == null)
100:                    _att.regExpRules = new Vector();
101:                _att.regExpRules.addElement(a);
102:            }
103:
104:            void addJavascriptRule(ValidatorJavascriptTag.Attributes a) {
105:                if (_att.javascriptRules == null)
106:                    _att.javascriptRules = new Vector();
107:                _att.javascriptRules.addElement(a);
108:            }
109:
110:            void addRequiredRule(ValidatorRequiredTag.Attributes a) {
111:                if (_att.requiredRules == null)
112:                    _att.requiredRules = new Vector();
113:                _att.requiredRules.addElement(a);
114:            }
115:
116:            /**
117:             * @see com.salmonllc.jsp.tags.BaseBodyTag#afterInit(HtmlComponent)
118:             */
119:            public void afterInit(HtmlComponent comp) {
120:                _att.name = getName();
121:                getHelper().getTagContext().addValidatorTag(_att);
122:                _att = new Attributes();
123:            }
124:
125:            /**
126:             * @see com.salmonllc.jsp.tags.BaseBodyTag#createComponent()
127:             */
128:            public HtmlComponent createComponent() {
129:                HtmlValidatorText v = null;
130:                if (_att.validatorClass != null)
131:                    v = buildComponent();
132:                if (v == null)
133:                    v = new HtmlValidatorText(getName(), _att.font, getHelper()
134:                            .getController());
135:                v.setBreaksBefore(BaseTagHelper.stringToInt(_att.breaksbefore,
136:                        0));
137:                v
138:                        .setBreaksAfter(BaseTagHelper.stringToInt(
139:                                _att.breaksafter, 0));
140:                v.setBreaksBetween(BaseTagHelper.stringToInt(
141:                        _att.breaksbetween, 1));
142:                if (!BaseTagHelper.isEmpty(_att.dbprofile))
143:                    v.setDBProfile(_att.dbprofile);
144:                if (!BaseTagHelper.isEmpty(_att.validatenewrows))
145:                    v.setValidateNewRows(BaseTagHelper
146:                            .stringToBoolean(_att.validatenewrows));
147:                if (!BaseTagHelper.isEmpty(_att.autopopulatelookups))
148:                    v.setAutoPopulateLookups(BaseTagHelper
149:                            .stringToBoolean(_att.autopopulatelookups));
150:                if (!BaseTagHelper.isEmpty(_att.fixhtml))
151:                    v.setFixSpecialHtmlCharacters(BaseTagHelper
152:                            .stringToBoolean(_att.fixhtml));
153:                if (!BaseTagHelper.isEmpty(_att.fixhtml))
154:                    v.setFixSpecialHtmlCharacters(BaseTagHelper
155:                            .stringToBoolean(_att.fixhtml));
156:                if (!BaseTagHelper.isEmpty(_att.allowmultipleerrors))
157:                    v.setMultipleErrorsOK(BaseTagHelper.stringToBoolean(
158:                            _att.allowmultipleerrors, false));
159:                if (!BaseTagHelper.isEmpty(_att.datasource))
160:                    v.setDataSource(_att.datasource);
161:                if (!BaseTagHelper.isEmpty(_att.useAlertsForErrors))
162:                    v.setUseAlertsForErrors(BaseTagHelper.stringToBoolean(
163:                            _att.useAlertsForErrors, false));
164:                if (!BaseTagHelper.isEmpty(_att.addFocusLinksToErrors))
165:                    v.setAddFocusLinksToErrors(BaseTagHelper.stringToBoolean(
166:                            _att.addFocusLinksToErrors, false));
167:
168:                return v;
169:            }
170:
171:            /**
172:             * @see com.salmonllc.jsp.tags.BaseBodyTag#generateComponentHTML(JspWriter)
173:             */
174:            protected void generateComponentHTML(JspWriter w) throws Exception {
175:                if (getTagWriter().getDreamWeaverConv()) {
176:                    HtmlValidatorText v = (HtmlValidatorText) getHelper()
177:                            .getComponent();
178:                    v.setVisible(true);
179:                    v.setErrorMessage("Validator:" + v.getName());
180:                }
181:                super .generateComponentHTML(w);
182:            }
183:
184:            private HtmlValidatorText buildComponent() {
185:                try {
186:                    Class c = Class.forName(_att.validatorClass, true, Thread
187:                            .currentThread().getContextClassLoader());
188:                    Class[] parms = { String.class, String.class,
189:                            HtmlPage.class };
190:                    Constructor con = c.getConstructor(parms);
191:                    Object[] args = { getName(), _att.font,
192:                            getHelper().getController() };
193:                    return (HtmlValidatorText) con.newInstance(args);
194:                } catch (Exception e) {
195:                    MessageLog
196:                            .writeErrorMessage(
197:                                    "Error creating HtmlValidatorText component. Make sure the component exists and has a constructor with the arguments (String name, String font, HtmlPage p)",
198:                                    e, this );
199:                }
200:                return null;
201:            }
202:
203:            /**
204:             * @see com.salmonllc.jsp.tags.BaseBodyTag#getTagConvertType()
205:             */
206:            public int getTagConvertType() {
207:                return CONV_WRAP_ALL_NESTED;
208:            }
209:
210:            /**
211:             * This method is part of the JSP tag lib specification.
212:             */
213:
214:            public void release() {
215:                super .release();
216:            }
217:
218:            /**
219:             * Sets the autopopulatelookups.
220:             * @param autopopulatelookups The autopopulatelookups to set
221:             */
222:            public void setAutopopulatelookups(String autopopulatelookups) {
223:                _att.autopopulatelookups = autopopulatelookups;
224:            }
225:
226:            /**
227:             * Sets the breaksAfter.
228:             * @param breaksAfter The breaksAfter to set
229:             */
230:            public void setBreaksafter(String breaksAfter) {
231:                _att.breaksafter = breaksAfter;
232:            }
233:
234:            /**
235:             * Sets the breaks between.
236:             * @param breaksBetween The breaksAfter to set
237:             */
238:            public void setBreaksbetween(String breaksBetween) {
239:                _att.breaksbetween = breaksBetween;
240:            }
241:
242:            /**
243:             * Sets the fix html.
244:             * @param fix The breaksAfter to set
245:             */
246:            public void setFixhtml(String fix) {
247:                _att.fixhtml = fix;
248:            }
249:
250:            /**
251:             * Sets the allow multiples.
252:             * @param allowmultipleerrors
253:             */
254:            public void setAllowmultipleerrors(String allowmultipleerrors) {
255:                _att.allowmultipleerrors = allowmultipleerrors;
256:            }
257:
258:            /**
259:             * Sets the breaksBefore.
260:             * @param breaksBefore The breaksBefore to set
261:             */
262:            public void setBreaksbefore(String breaksBefore) {
263:                _att.breaksbefore = breaksBefore;
264:            }
265:
266:            /**
267:             * Sets the datasource.
268:             * @param datasource The datasource to set
269:             */
270:            public void setDatasource(String datasource) {
271:                _att.datasource = datasource;
272:            }
273:
274:            /**
275:             * Sets the dbprofile.
276:             * @param dbprofile The dbprofile to set
277:             */
278:            public void setDbprofile(String dbprofile) {
279:                _att.dbprofile = dbprofile;
280:            }
281:
282:            /**
283:             * Sets the font.
284:             * @param font The font to set
285:             */
286:            public void setFont(String font) {
287:                _att.font = font;
288:            }
289:
290:            /**
291:             * Sets the submitcomponents.
292:             * @param submitcomponents The submitcomponents to set
293:             */
294:            public void setSubmitcomponents(String submitcomponents) {
295:                _att.submitcomponents = submitcomponents;
296:            }
297:
298:            /**
299:             * Sets up a validator. This is called after the page is initialized because the validator needs other components in the page
300:             */
301:            public static void setUpValidator(Attributes att,
302:                    HtmlValidatorText val, JspController cont)
303:                    throws DataStoreException {
304:
305:                boolean useJavaScriptForRules = BaseTagHelper.stringToBoolean(
306:                        att.useJavaScriptForRules, false);
307:                boolean useJavascriptForRangeRules = BaseTagHelper
308:                        .stringToBoolean(att.useJavaScriptForRangeRules, false);
309:                boolean useJavascriptForRegExpRules = BaseTagHelper
310:                        .stringToBoolean(att.useJavaScriptForRegExpRules, false);
311:                boolean useJavascriptForReqRules = BaseTagHelper
312:                        .stringToBoolean(att.useJavaScriptForRequiredRules,
313:                                false);
314:                boolean useJavascriptForValidationsOnly = BaseTagHelper
315:                        .stringToBoolean(att.useJavaScriptForValidationsOnly,
316:                                false);
317:                int jsRuleCount = (att.javascriptRules != null ? att.javascriptRules
318:                        .size()
319:                        : 0);
320:                int ruleCount = (att.typeCheckRules != null ? att.typeCheckRules
321:                        .size()
322:                        : 0)
323:                        + (att.expRules != null ? att.expRules.size() : 0)
324:                        + (att.lookupRules != null ? att.lookupRules.size() : 0);
325:
326:                if (useJavaScriptForRules || useJavascriptForRangeRules)
327:                    jsRuleCount += (att.rangeRules != null ? att.rangeRules
328:                            .size() : 0);
329:                else
330:                    ruleCount += (att.rangeRules != null ? att.rangeRules
331:                            .size() : 0);
332:
333:                if (useJavaScriptForRules || useJavascriptForRegExpRules)
334:                    jsRuleCount += (att.regExpRules != null ? att.regExpRules
335:                            .size() : 0);
336:                else
337:                    ruleCount += (att.regExpRules != null ? att.regExpRules
338:                            .size() : 0);
339:
340:                if (useJavaScriptForRules || useJavascriptForReqRules)
341:                    jsRuleCount += (att.requiredRules != null ? att.requiredRules
342:                            .size()
343:                            : 0);
344:                else
345:                    ruleCount += (att.requiredRules != null ? att.requiredRules
346:                            .size() : 0);
347:
348:                if (useJavaScriptForRules || useJavascriptForRegExpRules)
349:                    jsRuleCount += (att.regExpRules != null ? att.regExpRules
350:                            .size() : 0);
351:                else
352:                    ruleCount += (att.regExpRules != null ? att.regExpRules
353:                            .size() : 0);
354:
355:                ruleCount += jsRuleCount;
356:
357:                // get the data store buffer
358:                DataStoreBuffer b = cont.getDataSource(att.datasource);
359:                if (b != null) {
360:                    val.setDataStore(b);
361:                    if (BaseTagHelper.stringToBoolean(att.autoImportRules,
362:                            false))
363:                        val.importRules(b);
364:                } else if (ruleCount > 0 && ruleCount > jsRuleCount)
365:                    throw new NullPointerException(
366:                            "A data source is required for a validator with rules. Validator:"
367:                                    + att.name);
368:
369:                //get the submit buttons
370:                if (att.submitcomponents != null) {
371:                    StringTokenizer st = new StringTokenizer(
372:                            att.submitcomponents, ",");
373:                    while (st.hasMoreTokens()) {
374:                        String tok = st.nextToken();
375:                        HtmlComponent comp = cont.getComponent(tok);
376:                        if (comp != null) {
377:                            if (comp instanceof  HtmlSubmitButton)
378:                                val
379:                                        .addSubmitToListenTo((HtmlSubmitButton) comp);
380:                            else if (comp instanceof  HtmlSubmitImage)
381:                                val.addSubmitToListenTo((HtmlSubmitImage) comp);
382:                            else if (comp instanceof  JspLink)
383:                                val.addSubmitToListenTo((JspLink) comp);
384:                            else
385:                                throw new ClassCastException("Error making: "
386:                                        + tok
387:                                        + " a submit object for validator: "
388:                                        + att.name);
389:                        }
390:                    }
391:                }
392:                //else if (ruleCount > 0)
393:                //throw new NullPointerException("A submit component source is required for a validator with rules. Validator:" + att.name);
394:
395:                //do the typecheck rules
396:                if (att.typeCheckRules != null) {
397:                    for (int i = 0; i < att.typeCheckRules.size(); i++) {
398:                        ValidatorTypeCheckTag.Attributes a = (ValidatorTypeCheckTag.Attributes) att.typeCheckRules
399:                                .elementAt(i);
400:                        HtmlComponent comp = cont.getComponent(a.focuscomp);
401:                        if (comp == null)
402:                            throw new NullPointerException(
403:                                    "Can't find focus component:"
404:                                            + a.focuscomp
405:                                            + " for type check rule for validator:"
406:                                            + att.name);
407:                        if (!(comp instanceof  HtmlFormComponent || comp instanceof  HtmlLookUpComponent))
408:                            throw new ClassCastException(
409:                                    "Error focus component:"
410:                                            + a.focuscomp
411:                                            + " must be an HtmlFormComponent for validator:"
412:                                            + att.name);
413:                        HtmlFormComponent formComp;
414:                        if (comp instanceof  HtmlLookUpComponent)
415:                            formComp = ((HtmlLookUpComponent) comp)
416:                                    .getEditField();
417:                        else
418:                            formComp = (HtmlFormComponent) comp;
419:                        val.addTypeCheckRule(formComp, a.message,
420:                                a.messagelocalekey);
421:                    }
422:                }
423:
424:                //do the required rules
425:                if (att.requiredRules != null) {
426:                    for (int i = 0; i < att.requiredRules.size(); i++) {
427:                        ValidatorRequiredTag.Attributes a = (ValidatorRequiredTag.Attributes) att.requiredRules
428:                                .elementAt(i);
429:                        HtmlComponent comp = cont.getComponent(a.focuscomp);
430:                        if (comp == null)
431:                            throw new NullPointerException(
432:                                    "Can't find focus component:"
433:                                            + a.focuscomp
434:                                            + " for type required rule for validator:"
435:                                            + att.name);
436:                        if (!(comp instanceof  HtmlFormComponent || comp instanceof  HtmlLookUpComponent))
437:                            throw new ClassCastException(
438:                                    "Error focus component:"
439:                                            + a.focuscomp
440:                                            + " must be an HtmlFormComponent for validator:"
441:                                            + att.name);
442:
443:                        HtmlFormComponent formComp;
444:                        if (comp instanceof  HtmlLookUpComponent)
445:                            formComp = ((HtmlLookUpComponent) comp)
446:                                    .getEditField();
447:                        else
448:                            formComp = (HtmlFormComponent) comp;
449:                        val.addRequiredRule(formComp, a.message,
450:                                a.messagelocalekey);
451:                    }
452:                }
453:                //do the expression rules
454:                if (att.expRules != null) {
455:                    for (int i = 0; i < att.expRules.size(); i++) {
456:                        ValidatorRuleTag.Attributes a = (ValidatorRuleTag.Attributes) att.expRules
457:                                .elementAt(i);
458:
459:                        HtmlComponent comp = null;
460:                        if (a.focuscomp != null) {
461:                            comp = cont.getComponent(a.focuscomp);
462:                            if (comp == null)
463:                                throw new NullPointerException(
464:                                        "Can't find focus component:"
465:                                                + a.focuscomp
466:                                                + " for expression rule for validator:"
467:                                                + att.name);
468:                            if (!(comp instanceof  HtmlFormComponent || comp instanceof  HtmlLookUpComponent))
469:                                throw new ClassCastException(
470:                                        "Error focus component:"
471:                                                + a.focuscomp
472:                                                + " must be an HtmlFormComponent for validator:"
473:                                                + att.name);
474:                        }
475:                        HtmlFormComponent formComp;
476:                        if (comp instanceof  HtmlLookUpComponent)
477:                            formComp = ((HtmlLookUpComponent) comp)
478:                                    .getEditField();
479:                        else
480:                            formComp = (HtmlFormComponent) comp;
481:                        val.addExpressionRule(cont
482:                                .convertExpressionOperators(a.expression),
483:                                a.message, a.messagelocalekey, formComp);
484:                    }
485:                }
486:
487:                //do the regular expression rules
488:                if (att.regExpRules != null) {
489:                    for (int i = 0; i < att.regExpRules.size(); i++) {
490:                        ValidatorRegExpTag.Attributes a = (ValidatorRegExpTag.Attributes) att.regExpRules
491:                                .elementAt(i);
492:
493:                        HtmlComponent comp = null;
494:                        if (a.focuscomp != null) {
495:                            comp = cont.getComponent(a.focuscomp);
496:                            if (comp == null)
497:                                throw new NullPointerException(
498:                                        "Can't find focus component:"
499:                                                + a.focuscomp
500:                                                + " for regular expression rule for validator:"
501:                                                + att.name);
502:                            if (!(comp instanceof  HtmlFormComponent || comp instanceof  HtmlLookUpComponent))
503:                                throw new ClassCastException(
504:                                        "Error focus component:"
505:                                                + a.focuscomp
506:                                                + " must be an HtmlFormComponent for validator:"
507:                                                + att.name);
508:                        }
509:                        HtmlFormComponent formComp;
510:                        if (comp instanceof  HtmlLookUpComponent)
511:                            formComp = ((HtmlLookUpComponent) comp)
512:                                    .getEditField();
513:                        else
514:                            formComp = (HtmlFormComponent) comp;
515:                        val.addRegularExpressionRule(a.expression, a.message,
516:                                a.messagelocalekey, formComp);
517:                    }
518:                }
519:                //do the javascript rules
520:                if (att.javascriptRules != null) {
521:                    for (int i = 0; i < att.javascriptRules.size(); i++) {
522:                        ValidatorJavascriptTag.Attributes a = (ValidatorJavascriptTag.Attributes) att.javascriptRules
523:                                .elementAt(i);
524:
525:                        HtmlComponent comp = null;
526:                        if (a.focuscomp != null) {
527:                            comp = cont.getComponent(a.focuscomp);
528:                            if (comp == null)
529:                                throw new NullPointerException(
530:                                        "Can't find focus component:"
531:                                                + a.focuscomp
532:                                                + " for javascript rule for validator:"
533:                                                + att.name);
534:                            if (!(comp instanceof  HtmlFormComponent || comp instanceof  HtmlLookUpComponent))
535:                                throw new ClassCastException(
536:                                        "Error focus component:"
537:                                                + a.focuscomp
538:                                                + " must be an HtmlFormComponent for validator:"
539:                                                + att.name);
540:                        }
541:
542:                        HtmlFormComponent formComp;
543:                        if (comp instanceof  HtmlLookUpComponent)
544:                            formComp = ((HtmlLookUpComponent) comp)
545:                                    .getEditField();
546:                        else
547:                            formComp = (HtmlFormComponent) comp;
548:                        val.addJavascriptRule(a.javascript, a.message,
549:                                a.messagelocalekey, formComp);
550:                    }
551:                }
552:
553:                //do the lookup rules
554:                if (att.lookupRules != null) {
555:                    for (int i = 0; i < att.lookupRules.size(); i++) {
556:                        ValidatorLookupTag.Attributes a = (ValidatorLookupTag.Attributes) att.lookupRules
557:                                .elementAt(i);
558:
559:                        HtmlComponent comp = null;
560:                        if (a.focuscomp != null) {
561:                            comp = cont.getComponent(a.focuscomp);
562:                            if (comp == null)
563:                                throw new NullPointerException(
564:                                        "Can't find focus component:"
565:                                                + a.focuscomp
566:                                                + " for expression rule for validator:"
567:                                                + att.name);
568:                            if (!(comp instanceof  HtmlFormComponent || comp instanceof  HtmlLookUpComponent))
569:                                throw new ClassCastException(
570:                                        "Error focus component:"
571:                                                + a.focuscomp
572:                                                + " must be an HtmlFormComponent for validator:"
573:                                                + att.name);
574:                        }
575:
576:                        HtmlFormComponent formComp;
577:                        if (comp instanceof  HtmlLookUpComponent)
578:                            formComp = ((HtmlLookUpComponent) comp)
579:                                    .getEditField();
580:                        else
581:                            formComp = (HtmlFormComponent) comp;
582:                        val
583:                                .addLookupRule(
584:                                        a.lookupfromtable,
585:                                        cont
586:                                                .convertExpressionOperators(a.lookupwhereexpression),
587:                                        a.message, formComp,
588:                                        a.descriptionsource,
589:                                        a.descriptiontarget);
590:                    }
591:                }
592:
593:                //do the range rules
594:                if (att.rangeRules != null) {
595:                    for (int i = 0; i < att.rangeRules.size(); i++) {
596:                        ValidatorRangeTag.Attributes a = (ValidatorRangeTag.Attributes) att.rangeRules
597:                                .elementAt(i);
598:
599:                        HtmlComponent comp = null;
600:                        if (a.focuscomp != null) {
601:                            comp = cont.getComponent(a.focuscomp);
602:                            if (comp == null)
603:                                throw new NullPointerException(
604:                                        "Can't find focus component:"
605:                                                + a.focuscomp
606:                                                + " for range rule for validator:"
607:                                                + att.name);
608:                            if (!(comp instanceof  HtmlFormComponent))
609:                                throw new ClassCastException(
610:                                        "Error focus component:"
611:                                                + a.focuscomp
612:                                                + " must be an HtmlFormComponent for validator:"
613:                                                + att.name);
614:                        }
615:                        int dataType = DataStoreBuffer.DATATYPE_STRING;
616:                        if (val.getDataStore() != null)
617:                            dataType = val.getDataStore().getColumnDataType(
618:                                    ((HtmlFormComponent) comp)
619:                                            .getColumnNumber());
620:                        try {
621:                            val.addRangeRule(DataStoreBuffer.convertValue(
622:                                    a.minimum, dataType), DataStoreBuffer
623:                                    .convertValue(a.maximum, dataType),
624:                                    a.message, a.messagelocalekey,
625:                                    (HtmlFormComponent) comp);
626:                        } catch (Exception ex) {
627:                            throw new DataStoreException(
628:                                    "Error parsing value for range validation",
629:                                    ex);
630:                        }
631:                    }
632:                }
633:                if (!BaseTagHelper.isEmpty(att.useJavaScriptForRules))
634:                    val.setUseJavaScript(useJavaScriptForRules);
635:
636:                if (!BaseTagHelper.isEmpty(att.useJavaScriptForRangeRules))
637:                    val
638:                            .setUseJavaScriptForRangeRules(useJavascriptForRangeRules);
639:                if (!BaseTagHelper.isEmpty(att.useJavaScriptForRegExpRules))
640:                    val
641:                            .setUseJavaScriptForRegularExpRules(useJavascriptForRegExpRules);
642:                if (!BaseTagHelper.isEmpty(att.useJavaScriptForRequiredRules))
643:                    val
644:                            .setUseJavaScriptForRequiredRules(useJavascriptForReqRules);
645:                if (!BaseTagHelper.isEmpty(att.useJavaScriptForValidationsOnly))
646:                    val
647:                            .setUseJavaScriptForValidationsOnly(useJavascriptForValidationsOnly);
648:
649:            }
650:
651:            /**
652:             * Sets the validatenewrows.
653:             * @param validatenewrows The validatenewrows to set
654:             */
655:            public void setValidatenewrows(String validatenewrows) {
656:                _att.validatenewrows = validatenewrows;
657:            }
658:
659:            /**
660:             * Sets the validator class attribute
661:             * @param validatorClass
662:             */
663:            public void setValidatorclass(String validatorClass) {
664:                _att.validatorClass = validatorClass;
665:            }
666:
667:            public void setRulejs(String val) {
668:                _att.useJavaScriptForRules = val;
669:            }
670:
671:            public void setJavascriptforvalidationsonly(String val) {
672:                _att.useJavaScriptForValidationsOnly = val;
673:            }
674:
675:            public void setRangerulejs(String val) {
676:                _att.useJavaScriptForRangeRules = val;
677:            }
678:
679:            public void setRegexprulejs(String val) {
680:                _att.useJavaScriptForRegExpRules = val;
681:            }
682:
683:            public void setRequiredrulejs(String val) {
684:                _att.useJavaScriptForRequiredRules = val;
685:            }
686:
687:            public void setAlerts(String val) {
688:                _att.useAlertsForErrors = val;
689:            }
690:
691:            public void setFocuslinks(String val) {
692:                _att.addFocusLinksToErrors = val;
693:            }
694:
695:            public void setAutoimportrules(String val) {
696:                _att.autoImportRules = val;
697:            }
698:
699:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.