View Javadoc

1   /**
2    * Copyright 2005-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
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  package org.kuali.rice.krad.uif.element;
17  
18  import org.kuali.rice.krad.datadictionary.parse.BeanTag;
19  import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
20  import org.kuali.rice.krad.uif.component.Component;
21  import org.kuali.rice.krad.uif.util.ScriptUtils;
22  import org.kuali.rice.krad.uif.view.View;
23  
24  /**
25   * ValidationMessages for logic and options specific to groups
26   */
27  @BeanTag(name = "fieldValidationMessages", parent = "Uif-FieldValidationMessages")
28  public class FieldValidationMessages extends ValidationMessages{
29  
30      private boolean useTooltip;
31  
32      @Override
33      /**
34       * Calls super and add dataAttributes that are appropriate for field level validationMessages
35       * data.  This data is used by the validation framework clientside.
36       *
37       * @see krad.validate.js
38       */
39      public void generateMessages(boolean reset, View view, Object model, Component parent) {
40          super.generateMessages(reset, view, model, parent);
41          boolean hasMessages = false;
42          if(!this.getErrors().isEmpty() || !this.getWarnings().isEmpty() || !this.getInfos().isEmpty()){
43              hasMessages = true;
44          }
45          parent.addDataAttribute("validationMessages", "{"
46              + "displayMessages:" + this.isDisplayMessages() + ","
47              + "useTooltip:"+ useTooltip + ","
48              + "messagingEnabled:"+ this.isDisplayMessages() + ","
49              + "hasOwnMessages:"+ hasMessages + ","
50              + "serverErrors:" + ScriptUtils.convertStringListToJsArray(ScriptUtils.escapeHtml(this.getErrors())) + ","
51              + "serverWarnings:" + ScriptUtils.convertStringListToJsArray(ScriptUtils.escapeHtml(this.getWarnings())) + ","
52              + "serverInfo:" + ScriptUtils.convertStringListToJsArray(ScriptUtils.escapeHtml(this.getInfos()))
53              + "}");
54      }
55  
56  
57      /**
58       * When true, use the tooltip on fields to display their relevant messages.  When false, these messages
59       * will appear directly below the control.
60       *
61       * @return true if using tooltips for messages, false to display below control
62       */
63      @BeanTagAttribute(name="useTooltip")
64      public boolean isUseTooltip() {
65          return useTooltip;
66      }
67  
68      /**
69       * Set the useTooltip flag
70       *
71       * @param useTooltip - if true show tooltip, otherwise show messages below field control
72       */
73      public void setUseTooltip(boolean useTooltip) {
74          this.useTooltip = useTooltip;
75      }
76  
77  }