1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.util;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.core.api.config.property.ConfigurationService;
20 import org.kuali.rice.krad.datadictionary.validation.constraint.BaseConstraint;
21 import org.kuali.rice.krad.datadictionary.validation.constraint.CaseConstraint;
22 import org.kuali.rice.krad.datadictionary.validation.constraint.Constraint;
23 import org.kuali.rice.krad.datadictionary.validation.constraint.MustOccurConstraint;
24 import org.kuali.rice.krad.datadictionary.validation.constraint.PrerequisiteConstraint;
25 import org.kuali.rice.krad.datadictionary.validation.constraint.SimpleConstraint;
26 import org.kuali.rice.krad.datadictionary.validation.constraint.ValidCharactersConstraint;
27 import org.kuali.rice.krad.datadictionary.validation.constraint.WhenConstraint;
28 import org.kuali.rice.krad.service.KRADServiceLocator;
29 import org.kuali.rice.krad.uif.UifConstants;
30 import org.kuali.rice.krad.uif.field.InputField;
31 import org.kuali.rice.krad.uif.view.View;
32 import org.kuali.rice.krad.uif.control.TextControl;
33
34 import java.text.MessageFormat;
35 import java.util.ArrayList;
36 import java.util.EnumSet;
37 import java.util.List;
38
39
40
41
42
43
44
45
46 public class ClientValidationUtils {
47
48 private static int methodKey = 0;
49
50
51
52 private static List<List<String>> mustOccursPathNames;
53
54 public static final String LABEL_KEY_SPLIT_PATTERN = ",";
55
56
57 public static final String PREREQ_MSG_KEY = "prerequisite";
58 public static final String POSTREQ_MSG_KEY = "postrequisite";
59 public static final String MUSTOCCURS_MSG_KEY = "mustOccurs";
60 public static final String GENERIC_FIELD_MSG_KEY = "general.genericFieldName";
61
62 public static final String ALL_MSG_KEY = "general.all";
63 public static final String ATMOST_MSG_KEY = "general.atMost";
64 public static final String AND_MSG_KEY = "general.and";
65 public static final String OR_MSG_KEY = "general.or";
66
67 private static ConfigurationService configService = KRADServiceLocator.getKualiConfigurationService();
68
69
70 public static enum ValidationMessageKeys{
71 REQUIRED("required"),
72 MIN_EXCLUSIVE("minExclusive"),
73 MAX_INCLUSIVE("maxInclusive"),
74 MIN_LENGTH("minLengthConditional"),
75 MAX_LENGTH("maxLengthConditional");
76
77 private ValidationMessageKeys(String name) {
78 this.name = name;
79 }
80
81 private final String name;
82
83 @Override
84 public String toString() {
85 return name;
86 }
87
88 public static boolean contains(String name){
89 for (ValidationMessageKeys element : EnumSet.allOf(ValidationMessageKeys.class)) {
90 if (element.toString().equalsIgnoreCase(name)) {
91 return true;
92 }
93 }
94 return false;
95 }
96 }
97
98 public static String generateMessageFromLabelKey(List<String> params, String labelKey){
99 String message = "NO MESSAGE";
100 if(StringUtils.isNotEmpty(labelKey)){
101 message = configService.getPropertyValueAsString(labelKey);
102 if(params != null && !params.isEmpty() && StringUtils.isNotEmpty(message)){
103 message = MessageFormat.format(message, params.toArray());
104 }
105 }
106 if(StringUtils.isEmpty(message)){
107 message = labelKey;
108 }
109
110 if(message.contains("\"")){
111 message = message.replace("\"", """);
112 }
113 if(message.contains("'")){
114 message = message.replace("'", "'");
115 }
116 if(message.contains("\\")){
117 message = message.replace("\\", "\");
118 }
119 return message;
120 }
121
122
123
124
125
126
127
128 public static String generateValidatorMessagesOption(){
129 String mOption = "";
130 String keyValuePairs = "";
131 for(ValidationMessageKeys element : EnumSet.allOf(ValidationMessageKeys.class)){
132 String key = element.toString();
133 String message = configService.getPropertyValueAsString(UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + key);
134 if(StringUtils.isNotEmpty(message)){
135 keyValuePairs = keyValuePairs + "\n" + key + ": '"+ message + "',";
136
137 }
138
139 }
140 keyValuePairs = StringUtils.removeEnd(keyValuePairs, ",");
141 if(StringUtils.isNotEmpty(keyValuePairs)){
142 mOption="{" + keyValuePairs + "}";
143 }
144
145 return mOption;
146 }
147
148
149
150
151
152
153
154
155 public static String getRegexMethod(InputField field, ValidCharactersConstraint validCharactersConstraint) {
156 String message = generateMessageFromLabelKey(validCharactersConstraint.getValidationMessageParams(), validCharactersConstraint.getLabelKey());
157 String key = "validChar-" + field.getBindingInfo().getBindingPath() + methodKey;
158
159 String regex = validCharactersConstraint.getValue();
160
161 if(regex.contains("\\\\")){
162 regex = regex.replaceAll("\\\\", "\\\\\\\\");
163 }
164 if(regex.contains("/")){
165 regex = regex.replace("/", "\\/");
166 }
167
168 return "\njQuery.validator.addMethod(\"" + key
169 + "\", function(value, element) {\n "
170 + "return this.optional(element) || /" + regex + "/.test(value);"
171 + "}, \"" + message + "\");";
172 }
173
174
175
176
177
178
179
180
181
182 public static String getRegexMethodWithBooleanCheck(InputField field, ValidCharactersConstraint validCharactersConstraint) {
183 String message = generateMessageFromLabelKey(validCharactersConstraint.getValidationMessageParams(), validCharactersConstraint.getLabelKey());
184 String key = "validChar-" + field.getBindingInfo().getBindingPath() + methodKey;
185
186 String regex = validCharactersConstraint.getValue();
187
188 if(regex.contains("\\\\")){
189 regex = regex.replaceAll("\\\\", "\\\\\\\\");
190 }
191 if(regex.contains("/")){
192 regex = regex.replace("/", "\\/");
193 }
194
195 return "\njQuery.validator.addMethod(\"" + key
196 + "\", function(value, element, doCheck) {\n if(doCheck === false){return true;}else{"
197 + "return this.optional(element) || /" + regex + "/.test(value);}"
198 + "}, \"" + message + "\");";
199 }
200
201
202
203
204
205
206
207
208
209
210
211
212
213 public static void processCaseConstraint(InputField field, View view, CaseConstraint constraint, String andedCase) {
214 if (constraint.getOperator() == null) {
215 constraint.setOperator("equals");
216 }
217
218 String operator = "==";
219 if (constraint.getOperator().equalsIgnoreCase("not_equals")) {
220 operator = "!=";
221 }
222 else if (constraint.getOperator().equalsIgnoreCase("greater_than_equal")) {
223 operator = ">=";
224 }
225 else if (constraint.getOperator().equalsIgnoreCase("less_than_equal")) {
226 operator = "<=";
227 }
228 else if (constraint.getOperator().equalsIgnoreCase("greater_than")) {
229 operator = ">";
230 }
231 else if (constraint.getOperator().equalsIgnoreCase("less_than")) {
232 operator = "<";
233 }
234 else if (constraint.getOperator().equalsIgnoreCase("has_value")) {
235 operator = "";
236 }
237
238
239 field.getControl().addStyleClass("dependsOn-" + constraint.getPropertyName());
240
241 if (constraint.getWhenConstraint() != null && !constraint.getWhenConstraint().isEmpty()) {
242 String fieldPath = field.getBindingInfo().getBindingObjectPath() + "." + constraint.getPropertyName();
243 for (WhenConstraint wc : constraint.getWhenConstraint()) {
244 processWhenConstraint(field, view, constraint, wc, fieldPath, operator, andedCase);
245 }
246 }
247 }
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264 private static void processWhenConstraint(InputField field, View view, CaseConstraint caseConstraint, WhenConstraint wc, String fieldPath,
265 String operator, String andedCase) {
266 String ruleString = "";
267
268
269 String booleanStatement = "";
270 if (wc.getValues() != null) {
271
272 String caseStr = "";
273 if (!caseConstraint.isCaseSensitive()) {
274 caseStr = ".toUpperCase()";
275 }
276 for (int i = 0; i < wc.getValues().size(); i++) {
277 if (operator.isEmpty()) {
278
279 if (wc.getValues().get(i) instanceof String
280 && ((String) wc.getValues().get(i)).equalsIgnoreCase("false")) {
281 booleanStatement = booleanStatement + "(coerceValue('" + fieldPath + "') == '')";
282 }
283 else {
284 booleanStatement = booleanStatement + "(coerceValue('" + fieldPath + "') != '')";
285 }
286 }
287 else {
288
289 booleanStatement = booleanStatement + "(coerceValue('" + fieldPath + "')" + caseStr + " "
290 + operator + " \"" + wc.getValues().get(i) + "\"" + caseStr + ")";
291 }
292 if ((i + 1) != wc.getValues().size()) {
293 booleanStatement = booleanStatement + " || ";
294 }
295 }
296
297 }
298
299 if (andedCase != null) {
300 booleanStatement = "(" + booleanStatement + ") && (" + andedCase + ")";
301 }
302
303 if (wc.getConstraint() != null && StringUtils.isNotEmpty(booleanStatement)) {
304 ruleString = createRule(field, wc.getConstraint(), booleanStatement, view);
305 }
306
307 if (StringUtils.isNotEmpty(ruleString)) {
308 addScriptToPage(view, field, ruleString);
309 }
310 }
311
312
313
314
315
316
317
318
319
320 public static void addScriptToPage(View view, InputField field, String script) {
321 String prefixScript = "";
322
323 if (field.getOnDocumentReadyScript() != null) {
324 prefixScript = field.getOnDocumentReadyScript();
325 }
326 field.setOnDocumentReadyScript(prefixScript + "\n" + "runValidationScript(function(){" + script + "});");
327 }
328
329
330
331
332
333
334
335
336 private static List<String> parseOutFields(String statement){
337 List<String> fieldNames = new ArrayList<String>();
338 String[] splits = StringUtils.splitByWholeSeparator(statement, "coerceValue('");
339 for(String s: splits){
340 String fieldName = StringUtils.substringBefore(s, "'");
341 fieldNames.add(fieldName);
342 }
343 return fieldNames;
344 }
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365 @SuppressWarnings("boxing")
366 private static String createRule(InputField field, Constraint constraint, String booleanStatement, View view) {
367 String rule = "";
368 int constraintCount = 0;
369 if (constraint instanceof BaseConstraint && ((BaseConstraint) constraint).getApplyClientSide()) {
370 if (constraint instanceof SimpleConstraint) {
371 if (((SimpleConstraint) constraint).getRequired() != null && ((SimpleConstraint) constraint).getRequired()) {
372 rule = rule + "required: function(element){\nreturn (" + booleanStatement + ");}";
373
374 String showIndicatorScript = "";
375 for(String checkedField: parseOutFields(booleanStatement)){
376 showIndicatorScript = showIndicatorScript +
377 "setupShowReqIndicatorCheck('"+ checkedField +"', '" + field.getBindingInfo().getBindingPath() + "', " + "function(){\nreturn (" + booleanStatement + ");});\n";
378 }
379 addScriptToPage(view, field, showIndicatorScript);
380
381 constraintCount++;
382 }
383 if (((SimpleConstraint) constraint).getMinLength() != null) {
384 if (constraintCount > 0) {
385 rule = rule + ",\n";
386 }
387 rule = rule + "minLengthConditional: [" + ((SimpleConstraint) constraint).getMinLength()
388 + ", function(){return " + booleanStatement + ";}]";
389 constraintCount++;
390 }
391 if (((SimpleConstraint) constraint).getMaxLength() != null) {
392 if (constraintCount > 0) {
393 rule = rule + ",\n";
394 }
395 rule = rule + "maxLengthConditional: [" + ((SimpleConstraint) constraint).getMaxLength()
396 + ", function(){return " + booleanStatement + ";}]";
397 constraintCount++;
398 }
399
400 if (((SimpleConstraint) constraint).getExclusiveMin() != null) {
401 if (constraintCount > 0) {
402 rule = rule + ",\n";
403 }
404 rule = rule + "minExclusive: [" + ((SimpleConstraint) constraint).getExclusiveMin()
405 + ", function(){return " + booleanStatement + ";}]";
406 constraintCount++;
407 }
408
409 if (((SimpleConstraint) constraint).getInclusiveMax() != null) {
410 if (constraintCount > 0) {
411 rule = rule + ",\n";
412 }
413 rule = rule + "maxInclusive: [" + ((SimpleConstraint) constraint).getInclusiveMax()
414 + ", function(){return " + booleanStatement + ";}]";
415 constraintCount++;
416 }
417
418 rule = "jq('[name=\"" + field.getBindingInfo().getBindingPath() + "\"]').rules(\"add\", {" + rule + "\n});";
419 }
420 else if (constraint instanceof ValidCharactersConstraint) {
421 String regexMethod = "";
422 String methodName = "";
423 if(StringUtils.isNotEmpty(((ValidCharactersConstraint)constraint).getValue())) {
424 regexMethod = ClientValidationUtils.getRegexMethodWithBooleanCheck(field, (ValidCharactersConstraint) constraint) + "\n";
425 methodName = "validChar-" + field.getBindingInfo().getBindingPath() + methodKey;
426 methodKey++;
427 }
428 else {
429 if(StringUtils.isNotEmpty(((ValidCharactersConstraint)constraint).getLabelKey())){
430 methodName = ((ValidCharactersConstraint)constraint).getLabelKey();
431 }
432 }
433 if (StringUtils.isNotEmpty(methodName)) {
434 rule = regexMethod + "jq('[name=\"" + field.getBindingInfo().getBindingPath() + "\"]').rules(\"add\", {\n\"" + methodName
435 + "\" : function(element){return (" + booleanStatement + ");}\n});";
436 }
437 }
438 else if (constraint instanceof PrerequisiteConstraint) {
439 processPrerequisiteConstraint(field, (PrerequisiteConstraint) constraint, view, booleanStatement);
440 }
441 else if (constraint instanceof CaseConstraint) {
442 processCaseConstraint(field, view, (CaseConstraint) constraint, booleanStatement);
443 }
444 else if (constraint instanceof MustOccurConstraint) {
445 processMustOccurConstraint(field, view, (MustOccurConstraint) constraint, booleanStatement);
446 }
447 }
448 return rule;
449 }
450
451
452
453
454
455
456
457
458
459
460 public static void processPrerequisiteConstraint(InputField field, PrerequisiteConstraint constraint, View view) {
461 processPrerequisiteConstraint(field, constraint, view, "true");
462 }
463
464
465
466
467
468
469
470
471
472
473
474
475 public static void processPrerequisiteConstraint(InputField field, PrerequisiteConstraint constraint, View view, String booleanStatement) {
476 if (constraint != null && constraint.getApplyClientSide().booleanValue()) {
477 String dependsClass = "dependsOn-" + constraint.getPropertyName();
478 String addClass = "jq('[name=\""+ field.getBindingInfo().getBindingPath() + "\"]').addClass('" + dependsClass + "');" +
479 "jq('[name=\""+ constraint.getPropertyName() + "\"]').addClass('" + "dependsOn-" + field.getBindingInfo().getBindingPath() + "');";
480 addScriptToPage(view, field, addClass + getPrerequisiteStatement(field, view, constraint, booleanStatement)
481 + getPostrequisiteStatement(field, constraint, booleanStatement));
482
483 String showIndicatorScript = "setupShowReqIndicatorCheck('"+ field.getBindingInfo().getBindingPath() +"', '" + constraint.getPropertyName() + "', " + "function(){\nreturn (coerceValue('" + field.getBindingInfo().getBindingPath() + "') && " + booleanStatement + ");});\n";
484 addScriptToPage(view, field, showIndicatorScript);
485 }
486 }
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502 private static String getPrerequisiteStatement(InputField field, View view, PrerequisiteConstraint constraint, String booleanStatement) {
503 methodKey++;
504 String message = "";
505 if(StringUtils.isEmpty(constraint.getLabelKey())){
506 message = configService.getPropertyValueAsString(UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "prerequisite");
507 }
508 else{
509 message = generateMessageFromLabelKey(constraint.getValidationMessageParams(), constraint.getLabelKey());
510 }
511 if(StringUtils.isEmpty(message)){
512 message = "prerequisite - No message";
513 }
514 else{
515 InputField requiredField = (InputField) view.getViewIndex().getDataFieldByPath(constraint.getPropertyName());
516 if(requiredField != null && StringUtils.isNotEmpty(requiredField.getLabel())){
517 message = MessageFormat.format(message, requiredField.getLabel());
518 }
519 else{
520 message = MessageFormat.format(message, configService.getPropertyValueAsString(GENERIC_FIELD_MSG_KEY));
521 }
522 }
523
524
525 String methodName = "prConstraint-" + field.getBindingInfo().getBindingPath()+ methodKey;
526 String addClass = "jq('[name=\""+ field.getBindingInfo().getBindingPath() + "\"]').addClass('" + methodName + "');\n";
527 String method = "\njQuery.validator.addMethod(\""+ methodName +"\", function(value, element) {\n" +
528 " if(" + booleanStatement + "){ return (this.optional(element) || (coerceValue('" + constraint.getPropertyName() + "')));}else{return true;} " +
529 "}, \"" + message + "\");";
530
531 String ifStatement = "if(occursBefore('" + constraint.getPropertyName() + "','" + field.getBindingInfo().getBindingPath() +
532 "')){" + addClass + method + "}";
533 return ifStatement;
534 }
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549 private static String getPostrequisiteStatement(InputField field, PrerequisiteConstraint constraint, String booleanStatement) {
550
551 String message = "";
552 if(StringUtils.isEmpty(constraint.getLabelKey())){
553 message = configService.getPropertyValueAsString(UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "postrequisite");
554 }
555 else{
556 message = generateMessageFromLabelKey(constraint.getValidationMessageParams(), constraint.getLabelKey());
557 }
558
559 if(StringUtils.isEmpty(constraint.getLabelKey())){
560 if(StringUtils.isNotEmpty(field.getLabel())){
561 message = MessageFormat.format(message, field.getLabel());
562 }
563 else{
564 message = MessageFormat.format(message, configService.getPropertyValueAsString(GENERIC_FIELD_MSG_KEY));
565 }
566
567 }
568
569 String function = "function(element){\n" +
570 "return (coerceValue('"+ field.getBindingInfo().getBindingPath() + "') && " + booleanStatement + ");}";
571 String postStatement = "\nelse if(occursBefore('" + field.getBindingInfo().getBindingPath() + "','" + constraint.getPropertyName() +
572 "')){\njq('[name=\""+ constraint.getPropertyName() +
573 "\"]').rules(\"add\", { required: \n" + function
574 + ", \nmessages: {\nrequired: \""+ message +"\"}});}\n";
575
576 return postStatement;
577
578 }
579
580
581
582
583
584
585
586
587
588
589
590
591
592 public static void processMustOccurConstraint(InputField field, View view, MustOccurConstraint mc, String booleanStatement) {
593 methodKey++;
594 mustOccursPathNames = new ArrayList<List<String>>();
595
596 String methodName = "moConstraint-" + field.getBindingInfo().getBindingPath() + methodKey;
597 String method = "\njQuery.validator.addMethod(\""+ methodName +"\", function(value, element) {\n" +
598 " if(" + booleanStatement + "){return (this.optional(element) || ("+ getMustOccurStatement(field, mc) + "));}else{return true;}" +
599 "}, \"" + getMustOccursMessage(view, mc) +"\");";
600 String rule = method + "jq('[name=\""+ field.getBindingInfo().getBindingPath() + "\"]').rules(\"add\", {\n\"" + methodName + "\": function(element){return (" + booleanStatement + ");}\n});";
601 addScriptToPage(view, field, rule);
602 }
603
604
605
606
607
608
609
610
611
612
613
614 @SuppressWarnings("boxing")
615 private static String getMustOccurStatement(InputField field, MustOccurConstraint constraint) {
616 String statement = "";
617 List<String> attributePaths = new ArrayList<String>();
618 if (constraint != null && constraint.getApplyClientSide()) {
619 String array = "[";
620 if (constraint.getPrerequisiteConstraints() != null) {
621 for (int i = 0; i < constraint.getPrerequisiteConstraints().size(); i++) {
622 field.getControl().addStyleClass("dependsOn-"
623 + constraint.getPrerequisiteConstraints().get(i).getPropertyName());
624 array = array + "'" + constraint.getPrerequisiteConstraints().get(i).getPropertyName() + "'";
625 attributePaths.add(constraint.getPrerequisiteConstraints().get(i).getPropertyName());
626 if (i + 1 != constraint.getPrerequisiteConstraints().size()) {
627 array = array + ",";
628 }
629
630 }
631 }
632 array = array + "]";
633 statement = "mustOccurTotal(" + array + ", " + constraint.getMin() + ", " + constraint.getMax() + ")";
634
635 if(constraint.getMin()!=null){
636 attributePaths.add(constraint.getMin().toString());
637 }
638 else{
639 attributePaths.add(null);
640 }
641
642 if(constraint.getMax()!=null){
643 attributePaths.add(constraint.getMax().toString());
644 }
645 else{
646 attributePaths.add(null);
647 }
648
649 mustOccursPathNames.add(attributePaths);
650 if(StringUtils.isEmpty(statement)){
651 statement = "0";
652 }
653 if (constraint.getMustOccurConstraints() != null) {
654 for (MustOccurConstraint mc : constraint.getMustOccurConstraints()) {
655 statement = "mustOccurCheck(" + statement + " + " + getMustOccurStatement(field, mc) +
656 ", " + constraint.getMin() + ", " + constraint.getMax() + ")";
657 }
658 }
659 else{
660 statement = "mustOccurCheck(" + statement +
661 ", " + constraint.getMin() + ", " + constraint.getMax() + ")";
662 }
663 }
664 return statement;
665 }
666
667
668
669
670
671
672
673
674
675
676
677 private static String getMustOccursMessage(View view, MustOccurConstraint constraint){
678 String message = "";
679 if(StringUtils.isNotEmpty(constraint.getLabelKey())){
680 message = generateMessageFromLabelKey(constraint.getValidationMessageParams(), constraint.getLabelKey());
681 }
682 else{
683 String and = configService.getPropertyValueAsString(AND_MSG_KEY);
684 String or = configService.getPropertyValueAsString(OR_MSG_KEY);
685 String all = configService.getPropertyValueAsString(ALL_MSG_KEY);
686 String atMost = configService.getPropertyValueAsString(ATMOST_MSG_KEY);
687 String genericLabel = configService.getPropertyValueAsString(GENERIC_FIELD_MSG_KEY);
688 String mustOccursMsg = configService.getPropertyValueAsString(
689 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + MUSTOCCURS_MSG_KEY);
690
691 String statement="";
692 for(int i=0; i< mustOccursPathNames.size(); i++){
693 String andedString = "";
694
695 List<String> paths = mustOccursPathNames.get(i);
696 if(!paths.isEmpty()){
697
698 String min = paths.get(paths.size()-2);
699 String max = paths.get(paths.size()-1);
700 for(int j=0; j<paths.size()-2;j++){
701 InputField field = (InputField) view.getViewIndex().getDataFieldByPath(paths.get(j).trim());
702 String label = genericLabel;
703 if(field != null && StringUtils.isNotEmpty(field.getLabel())){
704 label = field.getLabel();
705 }
706 if(min.equals(max)){
707 if(j==0){
708 andedString = label;
709 }
710 else if(j==paths.size()-3){
711 andedString = andedString + " " + and + " " + label;
712 }
713 else{
714 andedString = andedString + ", " + label;
715 }
716 }
717 else{
718 andedString = andedString + "<li>" + label + "</li>";
719 }
720 }
721 if(min.equals(max)){
722 andedString = "<li>" + andedString + "</li>";
723 }
724 andedString="<ul>" + andedString + "</ul>";
725
726 if(StringUtils.isNotEmpty(min) && StringUtils.isNotEmpty(max) && !min.equals(max)){
727 andedString = MessageFormat.format(mustOccursMsg, min + "-" + max) + "<br/>" +andedString;
728 }
729 else if(StringUtils.isNotEmpty(min) && StringUtils.isNotEmpty(max) && min.equals(max) && i==0){
730 andedString = MessageFormat.format(mustOccursMsg, all) + "<br/>" +andedString;
731 }
732 else if(StringUtils.isNotEmpty(min) && StringUtils.isNotEmpty(max) && min.equals(max) && i!=0){
733
734 }
735 else if(StringUtils.isNotEmpty(min)){
736 andedString = MessageFormat.format(mustOccursMsg, min) + "<br/>" +andedString;
737 }
738 else if(StringUtils.isNotEmpty(max)){
739 andedString = MessageFormat.format(mustOccursMsg, atMost + " " + max) + "<br/>" +andedString;
740 }
741 }
742 if(StringUtils.isNotEmpty(andedString)){
743 if(i==0){
744 statement = andedString;
745 }
746 else{
747 statement = statement + or.toUpperCase() + andedString;
748 }
749 }
750 }
751 if(StringUtils.isNotEmpty(statement)){
752 message = statement;
753 }
754 }
755
756 return message;
757 }
758
759
760
761
762
763
764
765
766
767 @SuppressWarnings("boxing")
768 public static void processAndApplyConstraints(InputField field, View view) {
769 methodKey = 0;
770 if ((field.getRequired() != null) && (field.getRequired().booleanValue())) {
771 field.getControl().addStyleClass("required");
772 }
773
774 if (field.getExclusiveMin() != null) {
775 if (field.getControl() instanceof TextControl && ((TextControl) field.getControl()).getDatePicker() != null) {
776 ((TextControl) field.getControl()).getDatePicker().getComponentOptions().put("minDate", field.getExclusiveMin());
777 }
778 else{
779 String rule = "jq('[name=\""+ field.getBindingInfo().getBindingPath() + "\"]').rules(\"add\", {\n minExclusive: ["+ field.getExclusiveMin() + "]});";
780 addScriptToPage(view, field, rule);
781 }
782 }
783
784 if (field.getInclusiveMax() != null) {
785 if (field.getControl() instanceof TextControl && ((TextControl) field.getControl()).getDatePicker() != null) {
786 ((TextControl) field.getControl()).getDatePicker().getComponentOptions().put("maxDate", field.getInclusiveMax());
787 }
788 else{
789 String rule = "jq('[name=\""+ field.getBindingInfo().getBindingPath() + "\"]').rules(\"add\", {\n maxInclusive: ["+ field.getInclusiveMax() + "]});";
790 addScriptToPage(view, field, rule);
791 }
792 }
793
794 if (field.getValidCharactersConstraint() != null && field.getValidCharactersConstraint().getApplyClientSide()) {
795 if(StringUtils.isNotEmpty(field.getValidCharactersConstraint().getValue())) {
796
797 addScriptToPage(view, field, ClientValidationUtils.getRegexMethod(field, field.getValidCharactersConstraint()));
798 field.getControl().addStyleClass("validChar-" + field.getBindingInfo().getBindingPath()+ methodKey);
799 methodKey++;
800 }
801 else {
802
803 if(StringUtils.isNotEmpty(field.getValidCharactersConstraint().getLabelKey())){
804 field.getControl().addStyleClass(field.getValidCharactersConstraint().getLabelKey());
805 }
806 }
807 }
808
809 if (field.getCaseConstraint() != null && field.getCaseConstraint().getApplyClientSide()) {
810 processCaseConstraint(field, view, field.getCaseConstraint(), null);
811 }
812
813 if (field.getDependencyConstraints() != null) {
814 for (PrerequisiteConstraint prc : field.getDependencyConstraints()) {
815 processPrerequisiteConstraint(field, prc, view);
816 }
817 }
818
819 if (field.getMustOccurConstraints() != null) {
820 for (MustOccurConstraint mc : field.getMustOccurConstraints()) {
821 processMustOccurConstraint(field, view, mc, "true");
822 }
823 }
824
825 }
826
827 }