001 /**
002 * Copyright 2005-2013 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.krad.uif.element;
017
018 import org.kuali.rice.krad.datadictionary.parse.BeanTag;
019 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
020 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
021 import org.kuali.rice.krad.uif.UifConstants;
022 import org.kuali.rice.krad.uif.component.Component;
023 import org.kuali.rice.krad.uif.util.ScriptUtils;
024 import org.kuali.rice.krad.uif.view.View;
025
026 import java.util.HashMap;
027 import java.util.Map;
028
029 /**
030 * ValidationMessages for logic and options specific to groups
031 */
032 @BeanTag(name = "fieldValidationMessages-bean", parent = "Uif-FieldValidationMessages")
033 public class FieldValidationMessages extends ValidationMessages {
034
035 private boolean useTooltip;
036 private boolean showIcons;
037
038 @Override
039 /**
040 * Calls super and add dataAttributes that are appropriate for field level validationMessages
041 * data. This data is used by the validation framework clientside.
042 *
043 * @see krad.validate.js
044 */
045 public void generateMessages(boolean reset, View view, Object model, Component parent) {
046 super.generateMessages(reset, view, model, parent);
047 boolean hasMessages = false;
048 if (!this.getErrors().isEmpty() || !this.getWarnings().isEmpty() || !this.getInfos().isEmpty()) {
049 hasMessages = true;
050 }
051 HashMap<String, Object> validationMessagesDataAttributes = new HashMap<String, Object>();
052
053 Map<String, String> dataDefaults =
054 (Map<String, String>) (KRADServiceLocatorWeb.getDataDictionaryService().getDictionaryObject(
055 "Uif-FieldValidationMessages-DataDefaults"));
056
057 //display
058 this.addValidationDataSettingsValue(validationMessagesDataAttributes, dataDefaults, "displayMessages",
059 this.isDisplayMessages());
060
061 //options
062 this.addValidationDataSettingsValue(validationMessagesDataAttributes, dataDefaults, "useTooltip", useTooltip);
063 this.addValidationDataSettingsValue(validationMessagesDataAttributes, dataDefaults, "messagingEnabled",
064 this.isDisplayMessages());
065 this.addValidationDataSettingsValue(validationMessagesDataAttributes, dataDefaults, "hasOwnMessages",
066 hasMessages);
067 this.addValidationDataSettingsValue(validationMessagesDataAttributes, dataDefaults, "showIcons", showIcons);
068
069 //add property directly for selections
070 if (hasMessages) {
071 parent.addDataAttribute(UifConstants.DataAttributes.HAS_MESSAGES, Boolean.toString(hasMessages));
072 }
073
074 //server messages
075 this.addValidationDataSettingsValue(validationMessagesDataAttributes, dataDefaults, "serverErrors",
076 ScriptUtils.escapeHtml(this.getErrors()));
077 this.addValidationDataSettingsValue(validationMessagesDataAttributes, dataDefaults, "serverWarnings",
078 ScriptUtils.escapeHtml(this.getWarnings()));
079 this.addValidationDataSettingsValue(validationMessagesDataAttributes, dataDefaults, "serverInfo",
080 ScriptUtils.escapeHtml(this.getInfos()));
081
082 if (!validationMessagesDataAttributes.isEmpty()) {
083 parent.addDataAttribute(UifConstants.DataAttributes.VALIDATION_MESSAGES, ScriptUtils.translateValue(
084 validationMessagesDataAttributes));
085 }
086 }
087
088 /**
089 * When true, use the tooltip on fields to display their relevant messages. When false, these messages
090 * will appear directly below the control.
091 *
092 * @return true if using tooltips for messages, false to display below control
093 */
094 @BeanTagAttribute(name = "useTooltip")
095 public boolean isUseTooltip() {
096 return useTooltip;
097 }
098
099 /**
100 * Set the useTooltip flag
101 *
102 * @param useTooltip if true, show tooltip, otherwise show messages below field control
103 */
104 public void setUseTooltip(boolean useTooltip) {
105 this.useTooltip = useTooltip;
106 }
107
108 /**
109 * If true, display dynamic icons next to fields which have messages. Otherwise, do not render these icons.
110 *
111 * @return true if icons will be displayed, false otherwise
112 */
113 @BeanTagAttribute(name = "showIcons")
114 public boolean isShowIcons() {
115 return showIcons;
116 }
117
118 /**
119 * Set whether field validation icons should display or not.
120 *
121 * @param showIcons
122 */
123 public void setShowIcons(boolean showIcons) {
124 this.showIcons = showIcons;
125 }
126
127 /**
128 * @see org.kuali.rice.krad.uif.component.ComponentBase#copy()
129 */
130 @Override
131 protected <T> void copyProperties(T component) {
132 super.copyProperties(component);
133 FieldValidationMessages fieldValidationMessagesCopy = (FieldValidationMessages) component;
134 fieldValidationMessagesCopy.setUseTooltip(this.useTooltip);
135 fieldValidationMessagesCopy.setShowIcons(this.showIcons);
136 }
137 }