Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
6 | Andrea | 1 | <#-- |
2 | /* |
||
3 | * $Id: Action.java 502296 2007-02-01 17:33:39Z niallp $ |
||
4 | * |
||
5 | * Licensed to the Apache Software Foundation (ASF) under one |
||
6 | * or more contributor license agreements. See the NOTICE file |
||
7 | * distributed with this work for additional information |
||
8 | * regarding copyright ownership. The ASF licenses this file |
||
9 | * to you under the Apache License, Version 2.0 (the |
||
10 | * "License"); you may not use this file except in compliance |
||
11 | * with the License. You may obtain a copy of the License at |
||
12 | * |
||
13 | * http://www.apache.org/licenses/LICENSE-2.0 |
||
14 | * |
||
15 | * Unless required by applicable law or agreed to in writing, |
||
16 | * software distributed under the License is distributed on an |
||
17 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
||
18 | * KIND, either express or implied. See the License for the |
||
19 | * specific language governing permissions and limitations |
||
20 | * under the License. |
||
21 | */ |
||
22 | --> |
||
23 | <#-- |
||
24 | START SNIPPET: supported-validators |
||
25 | Only the following validators are supported: |
||
26 | * required validator |
||
27 | * requiredstring validator |
||
28 | * stringlength validator |
||
29 | * regex validator |
||
30 | * email validator |
||
31 | * url validator |
||
32 | * int validator |
||
33 | * double validator |
||
34 | END SNIPPET: supported-validators |
||
35 | --> |
||
36 | <#if ((parameters.validate?default(false) == true) && (parameters.performValidation?default(false) == true))> |
||
37 | <script type="text/javascript"> |
||
38 | function validateForm_${parameters.id}() { |
||
39 | form = document.getElementById("${parameters.id}"); |
||
40 | clearErrorMessages(form); |
||
41 | clearErrorLabels(form); |
||
42 | |||
43 | var errors = false; |
||
44 | <#list parameters.tagNames as tagName> |
||
45 | <#list tag.getValidators("${tagName}") as validator> |
||
46 | // field name: ${validator.fieldName} |
||
47 | // validator name: ${validator.validatorType} |
||
48 | if (form.elements['${validator.fieldName}']) { |
||
49 | field = form.elements['${validator.fieldName}']; |
||
50 | var error = "${validator.getMessage(action)?js_string}"; |
||
51 | <#if validator.validatorType = "required"> |
||
52 | if (field.value == "") { |
||
53 | addError(field, error); |
||
54 | errors = true; |
||
55 | } |
||
56 | <#elseif validator.validatorType = "requiredstring"> |
||
57 | if (field.value != null && (field.value == "" || field.value.replace(/^\s+|\s+$/g,"").length == 0)) { |
||
58 | addError(field, error); |
||
59 | errors = true; |
||
60 | } |
||
61 | <#elseif validator.validatorType = "stringlength"> |
||
62 | if (field.value != null) { |
||
63 | var value = field.value; |
||
64 | <#if validator.trim> |
||
65 | //trim field value |
||
66 | while (value.substring(0,1) == ' ') |
||
67 | value = value.substring(1, value.length); |
||
68 | while (value.substring(value.length-1, value.length) == ' ') |
||
69 | value = value.substring(0, value.length-1); |
||
70 | </#if> |
||
71 | if ((${validator.minLength?string} > -1 && value.length < ${validator.minLength?string}) || |
||
72 | (${validator.maxLength?string} > -1 && value.length > ${validator.maxLength?string})) { |
||
73 | addError(field, error); |
||
74 | errors = true; |
||
75 | } |
||
76 | } |
||
77 | <#elseif validator.validatorType = "regex"> |
||
78 | if (field.value != null && !field.value.match("${validator.expression?js_string}")) { |
||
79 | addError(field, error); |
||
80 | errors = true; |
||
81 | } |
||
82 | <#elseif validator.validatorType = "email"> |
||
83 | if (field.value != null && field.value.length > 0 && field.value.match(/\b(^[_A-Za-z0-9-]+(\.[_A-Za-z0-9-]+)*@([A-Za-z0-9-])+(\.[A-Za-z0-9-]+)*((\.[A-Za-z0-9]{2,})|(\.[A-Za-z0-9]{2,}\.[A-Za-z0-9]{2,}))$)\b/gi)==null) { |
||
84 | addError(field, error); |
||
85 | errors = true; |
||
86 | } |
||
87 | <#elseif validator.validatorType = "url"> |
||
88 | if (field.value != null && field.value.length > 0 && field.value.match(/(^(ftp|http|https):\/\/(\.[_A-Za-z0-9-]+)*(@?([A-Za-z0-9-])+)?(\.[A-Za-z0-9-]+)*((\.[A-Za-z0-9]{2,})|(\.[A-Za-z0-9]{2,}\.[A-Za-z0-9]{2,}))(:[0-9]+)?([/A-Za-z0-9?#_-]*)?$)/gi)==null) { |
||
89 | addError(field, error); |
||
90 | errors = true; |
||
91 | } |
||
92 | <#elseif validator.validatorType = "int"> |
||
93 | if (field.value != null) { |
||
94 | if (<#if validator.min?exists>parseInt(field.value) < |
||
95 | ${validator.min?string}<#else>false</#if> || |
||
96 | <#if validator.max?exists>parseInt(field.value) > |
||
97 | ${validator.max?string}<#else>false</#if>) { |
||
98 | addError(field, error); |
||
99 | errors = true; |
||
100 | } |
||
101 | } |
||
102 | <#elseif validator.validatorType = "double"> |
||
103 | if (field.value != null) { |
||
104 | var value = parseFloat(field.value); |
||
105 | if (<#if validator.minInclusive?exists>value < ${validator.minInclusive?string}<#else>false</#if> || |
||
106 | <#if validator.maxInclusive?exists>value > ${validator.maxInclusive?string}<#else>false</#if> || |
||
107 | <#if validator.minExclusive?exists>value <= ${validator.minExclusive?string}<#else>false</#if> || |
||
108 | <#if validator.maxExclusive?exists>value >= ${validator.maxExclusive?string}<#else>false</#if>) { |
||
109 | addError(field, error); |
||
110 | errors = true; |
||
111 | } |
||
112 | } |
||
113 | </#if> |
||
114 | } |
||
115 | </#list> |
||
116 | </#list> |
||
117 | |||
118 | return !errors; |
||
119 | } |
||
120 | </script> |
||
121 | </#if> |