KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > struts > faces > taglib > JavascriptValidatorTag


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.struts.faces.taglib;
18
19 import java.io.IOException JavaDoc;
20 import java.util.ArrayList JavaDoc;
21 import java.util.Collections JavaDoc;
22 import java.util.Comparator JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.List JavaDoc;
25 import java.util.Locale JavaDoc;
26 import java.util.Map JavaDoc;
27
28 import javax.faces.component.UIComponent;
29 import javax.faces.context.FacesContext;
30 import javax.faces.webapp.UIComponentTag;
31 import javax.servlet.http.HttpServletRequest JavaDoc;
32 import javax.servlet.jsp.JspException JavaDoc;
33 import javax.servlet.jsp.JspWriter JavaDoc;
34 import javax.servlet.jsp.PageContext JavaDoc;
35 import javax.servlet.jsp.tagext.BodyTagSupport JavaDoc;
36 import javax.servlet.jsp.tagext.Tag JavaDoc;
37
38 import org.apache.commons.validator.Field;
39 import org.apache.commons.validator.Form;
40 import org.apache.commons.validator.ValidatorAction;
41 import org.apache.commons.validator.ValidatorResources;
42 import org.apache.commons.validator.Var;
43 import org.apache.commons.validator.util.ValidatorUtils;
44 import org.apache.struts.Globals;
45 import org.apache.struts.config.ModuleConfig;
46 import org.apache.struts.faces.component.FormComponent;
47 import org.apache.struts.taglib.TagUtils;
48 import org.apache.struts.util.MessageResources;
49 import org.apache.struts.util.ModuleUtils;
50 import org.apache.struts.validator.Resources;
51 import org.apache.struts.validator.ValidatorPlugIn;
52
53 /**
54  * Custom tag that generates JavaScript for client side validation based
55  * on the validation rules loaded by the <code>ValidatorPlugIn</code>
56  * defined in the struts-config.xml file. This is based on the code in
57  * the corresponding class of the Struts HTML tag library, modified as needed
58  * to reflect differences in the way JavaServer Faces renders field
59  * identifiers.
60  *
61  * @version $Rev: 165410 $ $Date: 2005-04-30 17:25:14 +0100 (Sat, 30 Apr 2005) $
62  */

63 public class JavascriptValidatorTag extends BodyTagSupport JavaDoc {
64
65     // ----------------------------------------------------------- Properties
66

67     /**
68      * The servlet context attribute key for our resources.
69      */

70     protected String JavaDoc bundle = Globals.MESSAGES_KEY;
71
72     /**
73      * The default locale on our server.
74      * @deprecated This variable is no longer used.
75      */

76     protected static Locale JavaDoc defaultLocale = Locale.getDefault();
77
78     /**
79      * The name of the form that corresponds with the action name
80      * in struts-config.xml. Specifying a form name places a
81      * &lt;script&gt; &lt;/script&gt; around the javascript.
82      */

83     protected String JavaDoc formName = null;
84
85     /**
86      * The line ending string.
87      */

88     protected static String JavaDoc lineEnd = System.getProperty("line.separator");
89
90     /**
91      * The current page number of a multi-part form.
92      * Only valid when the formName attribute is set.
93      */

94     protected int page = 0;
95
96     /**
97      * This will be used as is for the JavaScript validation method name if it has a value. This is
98      * the method name of the main JavaScript method that the form calls to perform validations.
99      */

100     protected String JavaDoc methodName = null;
101
102     /**
103      * The static JavaScript methods will only be printed if this is set to "true".
104      */

105     protected String JavaDoc staticJavascript = "true";
106
107     /**
108      * The dynamic JavaScript objects will only be generated if this is set to "true".
109      */

110     protected String JavaDoc dynamicJavascript = "true";
111
112     /**
113      * The src attribute for html script element (used to include an external script
114      * resource). The src attribute is only recognized
115      * when the formName attribute is specified.
116      */

117     protected String JavaDoc src = null;
118
119     /**
120      * The JavaScript methods will enclosed with html comments if this is set to "true".
121      */

122     protected String JavaDoc htmlComment = "true";
123     
124     /**
125      * Hide JavaScript methods in a CDATA section for XHTML when "true".
126      */

127     protected String JavaDoc cdata = "true";
128
129     private String JavaDoc htmlBeginComment = "\n<!-- Begin \n";
130
131     private String JavaDoc htmlEndComment = "//End --> \n";
132     
133     /**
134      * Gets the key (form name) that will be used
135      * to retrieve a set of validation rules to be
136      * performed on the bean passed in for validation.
137      */

138     public String JavaDoc getFormName() {
139         return formName;
140     }
141
142     /**
143      * Sets the key (form name) that will be used
144      * to retrieve a set of validation rules to be
145      * performed on the bean passed in for validation.
146      * Specifying a form name places a
147      * &lt;script&gt; &lt;/script&gt; tag around the javascript.
148      */

149     public void setFormName(String JavaDoc formName) {
150         this.formName = formName;
151     }
152
153     /**
154      * Gets the current page number of a multi-part form.
155      * Only field validations with a matching page numer
156      * will be generated that match the current page number.
157      * Only valid when the formName attribute is set.
158      */

159     public int getPage() {
160         return page;
161     }
162
163     /**
164      * Sets the current page number of a multi-part form.
165      * Only field validations with a matching page numer
166      * will be generated that match the current page number.
167      * Only valid when the formName attribute is set.
168      */

169     public void setPage(int page) {
170         this.page = page;
171     }
172
173     /**
174      * Gets the method name that will be used for the Javascript
175      * validation method name if it has a value. This overrides
176      * the auto-generated method name based on the key (form name)
177      * passed in.
178      */

179     public String JavaDoc getMethod() {
180         return methodName;
181     }
182
183     /**
184      * Sets the method name that will be used for the Javascript
185      * validation method name if it has a value. This overrides
186      * the auto-generated method name based on the key (form name)
187      * passed in.
188      */

189     public void setMethod(String JavaDoc methodName) {
190         this.methodName = methodName;
191     }
192
193     /**
194      * Gets whether or not to generate the static
195      * JavaScript. If this is set to 'true', which
196      * is the default, the static JavaScript will be generated.
197      */

198     public String JavaDoc getStaticJavascript() {
199         return staticJavascript;
200     }
201
202     /**
203      * Sets whether or not to generate the static
204      * JavaScript. If this is set to 'true', which
205      * is the default, the static JavaScript will be generated.
206      */

207     public void setStaticJavascript(String JavaDoc staticJavascript) {
208         this.staticJavascript = staticJavascript;
209     }
210
211     /**
212      * Gets whether or not to generate the dynamic
213      * JavaScript. If this is set to 'true', which
214      * is the default, the dynamic JavaScript will be generated.
215      */

216     public String JavaDoc getDynamicJavascript() {
217         return dynamicJavascript;
218     }
219
220     /**
221      * Sets whether or not to generate the dynamic
222      * JavaScript. If this is set to 'true', which
223      * is the default, the dynamic JavaScript will be generated.
224      */

225     public void setDynamicJavascript(String JavaDoc dynamicJavascript) {
226         this.dynamicJavascript = dynamicJavascript;
227     }
228
229     /**
230       * Gets whether or not to delimit the
231       * JavaScript with html comments. If this is set to 'true', which
232       * is the default, the htmlComment will be surround the JavaScript.
233       */

234     public String JavaDoc getHtmlComment() {
235         return htmlComment;
236     }
237
238     /**
239      * Sets whether or not to delimit the
240      * JavaScript with html comments. If this is set to 'true', which
241      * is the default, the htmlComment will be surround the JavaScript.
242      */

243     public void setHtmlComment(String JavaDoc htmlComment) {
244         this.htmlComment = htmlComment;
245     }
246
247     /**
248      * Gets the src attribute's value when defining
249      * the html script element.
250      */

251     public String JavaDoc getSrc() {
252         return src;
253     }
254
255     /**
256      * Sets the src attribute's value when defining
257      * the html script element. The src attribute is only recognized
258      * when the formName attribute is specified.
259      */

260     public void setSrc(String JavaDoc src) {
261         this.src = src;
262     }
263
264     /**
265      * Render the JavaScript for to perform validations based on the form name.
266      *
267      * @exception JspException if a JSP exception has occurred
268      */

269     public int doStartTag() throws JspException JavaDoc {
270         StringBuffer JavaDoc results = new StringBuffer JavaDoc();
271
272         HttpServletRequest JavaDoc request = (HttpServletRequest JavaDoc)pageContext.getRequest();
273         ModuleConfig config = ModuleUtils.getInstance().getModuleConfig(request);
274         ValidatorResources resources =
275             (ValidatorResources) pageContext.getAttribute(
276                 ValidatorPlugIn.VALIDATOR_KEY + config.getPrefix(),
277                 PageContext.APPLICATION_SCOPE);
278
279         Locale JavaDoc locale = TagUtils.getInstance().getUserLocale(pageContext, null);
280
281         Form form = resources.getForm(locale, formName);
282         if (form != null) {
283             if ("true".equalsIgnoreCase(dynamicJavascript)) {
284                 MessageResources messages =
285                     (MessageResources) pageContext.getAttribute(
286                         bundle + config.getPrefix(),
287                         PageContext.APPLICATION_SCOPE);
288
289                 List JavaDoc lActions = new ArrayList JavaDoc();
290                 List JavaDoc lActionMethods = new ArrayList JavaDoc();
291
292                 // Get List of actions for this Form
293
for (Iterator JavaDoc i = form.getFields().iterator(); i.hasNext();) {
294                     Field field = (Field) i.next();
295
296                     for (Iterator JavaDoc x = field.getDependencyList().iterator(); x.hasNext();) {
297                         Object JavaDoc o = x.next();
298
299                         if (o != null && !lActionMethods.contains(o)) {
300                             lActionMethods.add(o);
301                         }
302                     }
303
304                 }
305
306                 // Create list of ValidatorActions based on lActionMethods
307
for (Iterator JavaDoc i = lActionMethods.iterator(); i.hasNext();) {
308                     String JavaDoc depends = (String JavaDoc) i.next();
309                     ValidatorAction va = resources.getValidatorAction(depends);
310
311                     // throw nicer NPE for easier debugging
312
if (va == null) {
313                         throw new NullPointerException JavaDoc(
314                             "Depends string \""
315                                 + depends
316                                 + "\" was not found in validator-rules.xml.");
317                     }
318                     
319                     String JavaDoc javascript = va.getJavascript();
320                     if (javascript != null && javascript.length() > 0) {
321                         lActions.add(va);
322                     } else {
323                         i.remove();
324                     }
325                 }
326
327                 Collections.sort(lActions, new Comparator JavaDoc() {
328                     public int compare(Object JavaDoc o1, Object JavaDoc o2) {
329                         ValidatorAction va1 = (ValidatorAction) o1;
330                         ValidatorAction va2 = (ValidatorAction) o2;
331
332                         if ((va1.getDepends() == null || va1.getDepends().length() == 0)
333                             && (va2.getDepends() == null || va2.getDepends().length() == 0)) {
334                             return 0;
335                         } else if (
336                             (va1.getDepends() != null && va1.getDepends().length() > 0)
337                                 && (va2.getDepends() == null || va2.getDepends().length() == 0)) {
338                             return 1;
339                         } else if (
340                             (va1.getDepends() == null || va1.getDepends().length() == 0)
341                                 && (va2.getDepends() != null && va2.getDepends().length() > 0)) {
342                             return -1;
343                         } else {
344                             return va1.getDependencyList().size() - va2.getDependencyList().size();
345                         }
346                     }
347                 });
348
349                 String JavaDoc methods = null;
350                 for (Iterator JavaDoc i = lActions.iterator(); i.hasNext();) {
351                     ValidatorAction va = (ValidatorAction) i.next();
352
353                     if (methods == null) {
354                         methods = va.getMethod() + "(form)";
355                     } else {
356                         methods += " && " + va.getMethod() + "(form)";
357                     }
358                 }
359
360                 results.append(getJavascriptBegin(methods));
361
362                 for (Iterator JavaDoc i = lActions.iterator(); i.hasNext();) {
363                     ValidatorAction va = (ValidatorAction) i.next();
364                     String JavaDoc jscriptVar = null;
365                     String JavaDoc functionName = null;
366
367                     if (va.getJsFunctionName() != null && va.getJsFunctionName().length() > 0) {
368                         functionName = va.getJsFunctionName();
369                     } else {
370                         functionName = va.getName();
371                     }
372
373                     if (isStruts11()) {
374                         results.append(" function " +
375                                        functionName + " () { \n");
376                     } else {
377                         results.append(" function " +
378                                        formName + "_" + functionName + " () { \n");
379                     }
380                     for (Iterator JavaDoc x = form.getFields().iterator(); x.hasNext();) {
381                         Field field = (Field) x.next();
382
383                         // Skip indexed fields for now until there is a good way to handle
384
// error messages (and the length of the list (could retrieve from scope?))
385
if (field.isIndexed()
386                             || field.getPage() != page
387                             || !field.isDependency(va.getName())) {
388                                 
389                             continue;
390                         }
391                         
392                         String JavaDoc message =
393                             Resources.getMessage(messages, locale, va, field);
394                         
395                         message = (message != null) ? message : "";
396
397                         jscriptVar = this.getNextVar(jscriptVar);
398
399                         results.append(
400                             " this."
401                                 + jscriptVar
402                                 + " = new Array(\""
403                                 + getFormClientId()
404                                 + ":"
405                                 + field.getKey()
406                                 + "\", \""
407                                 + message
408                                 + "\", ");
409
410                         results.append("new Function (\"varName\", \"");
411
412                         Map JavaDoc vars = field.getVars();
413                         // Loop through the field's variables.
414
Iterator JavaDoc varsIterator = vars.keySet().iterator();
415                         while (varsIterator.hasNext()) {
416                             String JavaDoc varName = (String JavaDoc) varsIterator.next();
417                             Var var = (Var) vars.get(varName);
418                             String JavaDoc varValue = var.getValue();
419                             String JavaDoc jsType = var.getJsType();
420
421                             // skip requiredif variables field, fieldIndexed, fieldTest, fieldValue
422
if (varName.startsWith("field")) {
423                                 continue;
424                             }
425
426                             if (Var.JSTYPE_INT.equalsIgnoreCase(jsType)) {
427                                 results.append(
428                                     "this."
429                                         + varName
430                                         + "="
431                                         + ValidatorUtils.replace(
432                                             varValue,
433                                             "\\",
434                                             "\\\\")
435                                         + "; ");
436                             } else if (Var.JSTYPE_REGEXP.equalsIgnoreCase(jsType)) {
437                                 results.append(
438                                     "this."
439                                         + varName
440                                         + "=/"
441                                         + ValidatorUtils.replace(
442                                             varValue,
443                                             "\\",
444                                             "\\\\")
445                                         + "/; ");
446                             } else if (Var.JSTYPE_STRING.equalsIgnoreCase(jsType)) {
447                                 results.append(
448                                     "this."
449                                         + varName
450                                         + "='"
451                                         + ValidatorUtils.replace(
452                                             varValue,
453                                             "\\",
454                                             "\\\\")
455                                         + "'; ");
456                                 // So everyone using the latest format doesn't need to change their xml files immediately.
457
} else if ("mask".equalsIgnoreCase(varName)) {
458                                 results.append(
459                                     "this."
460                                         + varName
461                                         + "=/"
462                                         + ValidatorUtils.replace(
463                                             varValue,
464                                             "\\",
465                                             "\\\\")
466                                         + "/; ");
467                             } else {
468                                 results.append(
469                                     "this."
470                                         + varName
471                                         + "='"
472                                         + ValidatorUtils.replace(
473                                             varValue,
474                                             "\\",
475                                             "\\\\")
476                                         + "'; ");
477                             }
478                         }
479
480                         results.append(" return this[varName];\"));\n");
481                     }
482                     results.append(" } \n\n");
483                 }
484             } else if ("true".equalsIgnoreCase(staticJavascript)) {
485                 results.append(this.getStartElement());
486                 if ("true".equalsIgnoreCase(htmlComment)) {
487                     results.append(htmlBeginComment);
488                 }
489             }
490         }
491         
492         if ("true".equalsIgnoreCase(staticJavascript)) {
493             results.append(getJavascriptStaticMethods(resources));
494         }
495
496         if (form != null
497             && ("true".equalsIgnoreCase(dynamicJavascript)
498                 || "true".equalsIgnoreCase(staticJavascript))) {
499                     
500             results.append(getJavascriptEnd());
501         }
502
503
504         JspWriter JavaDoc writer = pageContext.getOut();
505         try {
506             writer.print(results.toString());
507         } catch (IOException JavaDoc e) {
508             throw new JspException JavaDoc(e.getMessage());
509         }
510
511         return (EVAL_BODY_TAG);
512
513     }
514
515     /**
516      * Release any acquired resources.
517      */

518     public void release() {
519         super.release();
520         bundle = Globals.MESSAGES_KEY;
521         formName = null;
522         page = 0;
523         methodName = null;
524         staticJavascript = "true";
525         dynamicJavascript = "true";
526         htmlComment = "true";
527         cdata = "true";
528         src = null;
529         formClientId = null;
530     }
531
532     /**
533      * Returns the opening script element and some initial javascript.
534      */

535     protected String JavaDoc getJavascriptBegin(String JavaDoc methods) {
536         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
537         String JavaDoc name =
538             formName.substring(0, 1).toUpperCase()
539                 + formName.substring(1, formName.length());
540
541         sb.append(this.getStartElement());
542         
543         if (this.isXhtml() && "true".equalsIgnoreCase(this.cdata)) {
544             sb.append("<![CDATA[\r\n");
545         }
546         
547         if (!this.isXhtml() && "true".equals(htmlComment)) {
548             sb.append(htmlBeginComment);
549         }
550         sb.append("\n var bCancel = false; \n\n");
551
552         if (methodName == null || methodName.length() == 0) {
553             sb.append(
554                 " function validate"
555                     + name
556                     + "(form) { \n");
557         } else {
558             sb.append(
559                 " function "
560                     + methodName
561                     + "(form) { \n");
562         }
563         sb.append(" if (bCancel) \n");
564         sb.append(" return true; \n");
565         sb.append(" else \n");
566
567         // Always return true if there aren't any Javascript validation methods
568
if (methods == null || methods.length() == 0) {
569             sb.append(" return true; \n");
570         } else {
571             sb.append(" return " + methods + "; \n");
572         }
573
574         sb.append(" } \n\n");
575
576         return sb.toString();
577     }
578
579     protected String JavaDoc getJavascriptStaticMethods(ValidatorResources resources) {
580         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
581
582         sb.append("\n\n");
583
584         Iterator JavaDoc actions = resources.getValidatorActions().values().iterator();
585         while (actions.hasNext()) {
586             ValidatorAction va = (ValidatorAction) actions.next();
587             if (va != null) {
588                 String JavaDoc javascript = va.getJavascript();
589                 if (javascript != null && javascript.length() > 0) {
590                     sb.append(javascript + "\n");
591                 }
592             }
593         }
594
595         return sb.toString();
596     }
597
598     /**
599      * Returns the closing script element.
600      */

601     protected String JavaDoc getJavascriptEnd() {
602         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
603
604         sb.append("\n");
605         if (!this.isXhtml() && "true".equals(htmlComment)){
606             sb.append(htmlEndComment);
607         }
608         
609         if (this.isXhtml() && "true".equalsIgnoreCase(this.cdata)) {
610             sb.append("]]>\r\n");
611         }
612         
613         sb.append("</script>\n\n");
614
615         return sb.toString();
616     }
617
618     /**
619      * The value <code>null</code> will be returned at the end of the sequence.
620      * &nbsp;&nbsp;&nbsp; ex: "zz" will return <code>null</code>
621      */

622     private String JavaDoc getNextVar(String JavaDoc input) {
623         if (input == null) {
624             return "aa";
625         }
626
627         input = input.toLowerCase();
628
629         for (int i = input.length(); i > 0; i--) {
630             int pos = i - 1;
631
632             char c = input.charAt(pos);
633             c++;
634
635             if (c <= 'z') {
636                 if (i == 0) {
637                     return c + input.substring(pos, input.length());
638                 } else if (i == input.length()) {
639                     return input.substring(0, pos) + c;
640                 } else {
641                     return input.substring(0, pos) + c + input.substring(pos, input.length() - 1);
642                 }
643             } else {
644                 input = replaceChar(input, pos, 'a');
645             }
646
647         }
648
649         return null;
650
651     }
652
653     /**
654      * Replaces a single character in a <code>String</code>
655      */

656     private String JavaDoc replaceChar(String JavaDoc input, int pos, char c) {
657         if (pos == 0) {
658             return c + input.substring(pos, input.length());
659         } else if (pos == input.length()) {
660             return input.substring(0, pos) + c;
661         } else {
662             return input.substring(0, pos) + c + input.substring(pos, input.length() - 1);
663         }
664     }
665
666     /**
667      * Constructs the beginning &lt;script&gt; element depending on xhtml status.
668      */

669     private String JavaDoc getStartElement() {
670         StringBuffer JavaDoc start = new StringBuffer JavaDoc("<script type=\"text/javascript\"");
671
672         // there is no language attribute in xhtml
673
if (!this.isXhtml()) {
674             start.append(" language=\"Javascript1.1\"");
675         }
676
677         if (this.src != null) {
678             start.append(" SRC=\"" + src + "\"");
679         }
680
681         start.append("> \n");
682         return start.toString();
683     }
684     
685     /**
686      * Returns true if this is an xhtml page.
687      */

688     private boolean isXhtml() {
689         return TagUtils.getInstance().isXhtml(this.pageContext);
690     }
691
692     /**
693      * Returns the cdata setting "true" or "false".
694      * @return String - "true" if JavaScript will be hidden in a CDATA section
695      */

696     public String JavaDoc getCdata() {
697         return cdata;
698     }
699
700     /**
701      * Sets the cdata status.
702      * @param cdata The cdata to set
703      */

704     public void setCdata(String JavaDoc cdata) {
705         this.cdata = cdata;
706     }
707
708
709     private String JavaDoc formClientId = null;
710
711     /**
712      * <p>Return the <code>clientId</code> of the form component for which
713      * we are rendering validation Javascript.</p>
714      *
715      * @exception IllegalStateException if we are not nested inside a
716      * UIComponentTag with a child FormComponent matching our form name
717      */

718     private String JavaDoc getFormClientId(){
719
720         // Return any cached value
721
if (formClientId != null) {
722             return (formClientId);
723         }
724
725         // Locate our parent tag that is a component tag
726
Tag parent = getParent();
727         while (parent != null) {
728             if (parent instanceof UIComponentTag) {
729                 break;
730             }
731             parent = parent.getParent();
732         }
733         if (parent == null) {
734             throw new IllegalArgumentException JavaDoc
735                 ("Not nested inside a UIComponentTag");
736         }
737
738         // Are we nested inside our corresponding form tag?
739
UIComponent parentComponent =
740             ((UIComponentTag) parent).getComponentInstance();
741         if (parentComponent instanceof FormComponent) {
742             if (formName.equals(parentComponent.getAttributes().get("beanName"))) {
743                 formClientId = parentComponent.getClientId
744                     (FacesContext.getCurrentInstance());
745                 return (formClientId);
746             }
747         }
748
749         // Scan the children of this tag's component
750
Iterator JavaDoc kids = ((UIComponentTag) parent).
751             getComponentInstance().getChildren().iterator();
752         while (kids.hasNext()) {
753             UIComponent kid = (UIComponent) kids.next();
754             if (!(kid instanceof FormComponent)) {
755                 continue;
756             }
757             if (formName.equals(kid.getAttributes().get("beanName"))) {
758                 formClientId =
759                     kid.getClientId(FacesContext.getCurrentInstance());
760                 return (formClientId);
761             }
762         }
763         throw new IllegalArgumentException JavaDoc
764             ("Cannot find child FormComponent for form '" + formName + "'");
765
766     }
767
768
769     // ---------------------------------------------------------- Static Methods
770

771
772     private static boolean struts11;
773
774     static {
775         try {
776             JavascriptValidatorTag.class.getClassLoader().loadClass
777                 ("org.apache.struts.taglib.TagUtils");
778             struts11 = false;
779         } catch (Exception JavaDoc e) {
780             struts11 = true;
781         }
782     }
783
784
785     /**
786      * <p>Return <code>true</code> if we are running on top of Struts 1.1</p>
787      */

788     private static boolean isStruts11() {
789         return struts11;
790     }
791
792
793 }
794
Popular Tags