001/** 002 * Copyright 2005-2018 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 */ 016package org.kuali.rice.krad.uif.field; 017 018import java.util.List; 019 020import org.apache.commons.lang.StringUtils; 021import org.kuali.rice.krad.datadictionary.parse.BeanTag; 022import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute; 023import org.kuali.rice.krad.datadictionary.parse.BeanTags; 024import org.kuali.rice.krad.datadictionary.validator.ValidationTrace; 025import org.kuali.rice.krad.datadictionary.validator.Validator; 026import org.kuali.rice.krad.uif.UifConstants; 027import org.kuali.rice.krad.uif.component.Component; 028import org.kuali.rice.krad.uif.element.Message; 029import org.kuali.rice.krad.uif.util.LifecycleElement; 030 031/** 032 * Field wrapper for a Message. 033 * 034 * <p> 035 * The <code>Message</code> is used to display static text in the user 036 * interface 037 * </p> 038 * 039 * @author Kuali Rice Team (rice.collab@kuali.org) 040 */ 041@BeanTag(name = "messageField", parent = "Uif-MessageField") 042public class MessageField extends FieldBase { 043 private static final long serialVersionUID = -7045208136391722063L; 044 045 private Message message; 046 047 public MessageField() { 048 super(); 049 } 050 051 /** 052 * PerformFinalize override - calls super, corrects the field's Label for attribute to point to this field's content 053 * 054 * @param model the model 055 * @param parent the parent component 056 */ 057 @Override 058 public void performFinalize(Object model, LifecycleElement parent) { 059 super.performFinalize(model, parent); 060 061 //determine what id to use for the for attribute of the label, if present 062 if(this.getFieldLabel() != null && this.getMessage() != null 063 && StringUtils.isNotBlank(this.getMessage().getId())){ 064 065 if(this.getMessage().getMessageComponentStructure() != null 066 && !this.getMessage().getMessageComponentStructure().isEmpty()){ 067 //wrapper will be a rich message div - no suffix 068 this.getFieldLabel().setLabelForComponentId(this.getMessage().getId()); 069 } 070 else{ 071 //wrapper will be a normal message span - add suffix 072 this.getFieldLabel().setLabelForComponentId(this.getMessage().getId() + UifConstants.IdSuffixes.SPAN); 073 } 074 } 075 } 076 077 /** 078 * @see org.kuali.rice.krad.uif.element.Message#getMessageText() 079 */ 080 @BeanTagAttribute 081 public String getMessageText() { 082 if (message != null) { 083 return message.getMessageText(); 084 } 085 086 return null; 087 } 088 089 /** 090 * @see MessageField#getMessageText() 091 */ 092 public void setMessageText(String messageText) { 093 if (message != null) { 094 message.setMessageText(messageText); 095 } 096 } 097 098 /** 099 * @see org.kuali.rice.krad.uif.element.Message#getInlineComponents() 100 * @return 101 */ 102 @BeanTagAttribute 103 public List<Component> getInlineComponents() { 104 if (message != null) { 105 return message.getInlineComponents(); 106 } 107 108 return null; 109 } 110 111 /** 112 * @see MessageField#getInlineComponents() 113 */ 114 public void setInlineComponents(List<Component> inlineComponents) { 115 if (message != null) { 116 message.setInlineComponents(inlineComponents); 117 } 118 } 119 120 /** 121 * @see org.kuali.rice.krad.uif.element.Message#getMessageText() 122 */ 123 @BeanTagAttribute(type= BeanTagAttribute.AttributeType.DIRECTORBYTYPE) 124 public Message getMessage() { 125 return message; 126 } 127 128 /** 129 * @see MessageField#getMessage() 130 */ 131 public void setMessage(Message message) { 132 this.message = message; 133 } 134 135 /** 136 * {@inheritDoc} 137 */ 138 @Override 139 public void completeValidation(ValidationTrace tracer){ 140 tracer.addBean(this); 141 142 // Checks that the message is set 143 if(getMessage()==null){ 144 if(Validator.checkExpressions(this, "message")){ 145 String currentValues [] = {"message ="+getMessage()}; 146 tracer.createWarning("Message should not be null",currentValues); 147 } 148 } 149 150 // Checks that the label is set 151 if(getLabel()==null){ 152 if(Validator.checkExpressions(this, "label")){ 153 String currentValues [] = {"label ="+getLabel(),"Message ="+getMessage()}; 154 tracer.createWarning("Label is null, message should be used instead",currentValues); 155 } 156 } 157 158 super.completeValidation(tracer.getCopy()); 159 } 160}