1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.field;
17
18 import java.util.List;
19
20 import org.apache.commons.lang.StringUtils;
21 import org.kuali.rice.krad.datadictionary.parse.BeanTag;
22 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
23 import org.kuali.rice.krad.datadictionary.parse.BeanTags;
24 import org.kuali.rice.krad.datadictionary.validator.ValidationTrace;
25 import org.kuali.rice.krad.datadictionary.validator.Validator;
26 import org.kuali.rice.krad.uif.UifConstants;
27 import org.kuali.rice.krad.uif.component.Component;
28 import org.kuali.rice.krad.uif.element.Message;
29 import org.kuali.rice.krad.uif.util.LifecycleElement;
30
31
32
33
34
35
36
37
38
39
40
41 @BeanTag(name = "messageField", parent = "Uif-MessageField")
42 public class MessageField extends FieldBase {
43 private static final long serialVersionUID = -7045208136391722063L;
44
45 private Message message;
46
47 public MessageField() {
48 super();
49 }
50
51
52
53
54
55
56
57 @Override
58 public void performFinalize(Object model, LifecycleElement parent) {
59 super.performFinalize(model, parent);
60
61
62 if(this.getFieldLabel() != null && this.getMessage() != null
63 && StringUtils.isNotBlank(this.getMessage().getId())){
64
65 if(this.getMessage().getMessageComponentStructure() != null
66 && !this.getMessage().getMessageComponentStructure().isEmpty()){
67
68 this.getFieldLabel().setLabelForComponentId(this.getMessage().getId());
69 }
70 else{
71
72 this.getFieldLabel().setLabelForComponentId(this.getMessage().getId() + UifConstants.IdSuffixes.SPAN);
73 }
74 }
75 }
76
77
78
79
80 @BeanTagAttribute
81 public String getMessageText() {
82 if (message != null) {
83 return message.getMessageText();
84 }
85
86 return null;
87 }
88
89
90
91
92 public void setMessageText(String messageText) {
93 if (message != null) {
94 message.setMessageText(messageText);
95 }
96 }
97
98
99
100
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
113
114 public void setInlineComponents(List<Component> inlineComponents) {
115 if (message != null) {
116 message.setInlineComponents(inlineComponents);
117 }
118 }
119
120
121
122
123 @BeanTagAttribute(type= BeanTagAttribute.AttributeType.DIRECTORBYTYPE)
124 public Message getMessage() {
125 return message;
126 }
127
128
129
130
131 public void setMessage(Message message) {
132 this.message = message;
133 }
134
135
136
137
138 @Override
139 public void completeValidation(ValidationTrace tracer){
140 tracer.addBean(this);
141
142
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
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 }