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 org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.krad.datadictionary.parse.BeanTag;
20 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
21 import org.kuali.rice.krad.datadictionary.parse.BeanTags;
22 import org.kuali.rice.krad.datadictionary.validator.ErrorReport;
23 import org.kuali.rice.krad.datadictionary.validator.Validator;
24 import org.kuali.rice.krad.datadictionary.validator.ValidationTrace;
25 import org.kuali.rice.krad.uif.UifConstants;
26 import org.kuali.rice.krad.uif.component.Component;
27 import org.kuali.rice.krad.uif.container.Container;
28 import org.kuali.rice.krad.uif.element.Message;
29 import org.kuali.rice.krad.uif.view.View;
30
31 import java.util.ArrayList;
32 import java.util.List;
33
34
35
36
37
38
39
40
41
42
43
44 @BeanTags({@BeanTag(name = "messageField-bean", parent = "Uif-MessageField"),
45 @BeanTag(name = "colGroupingField-bean", parent = "Uif-ColGroupingField")})
46 public class MessageField extends FieldBase {
47 private static final long serialVersionUID = -7045208136391722063L;
48
49 private Message message;
50
51 public MessageField() {
52 super();
53 }
54
55
56
57
58 @Override
59 public List<Component> getComponentsForLifecycle() {
60 List<Component> components = super.getComponentsForLifecycle();
61
62 components.add(message);
63
64 return components;
65 }
66
67
68
69
70
71
72
73
74 @Override
75 public void performFinalize(View view, Object model, Component parent) {
76 super.performFinalize(view, model, parent);
77
78
79 if(this.getFieldLabel() != null && this.getMessage() != null
80 && StringUtils.isNotBlank(this.getMessage().getId())){
81
82 if(this.getMessage().getMessageComponentStructure() != null
83 && !this.getMessage().getMessageComponentStructure().isEmpty()){
84
85 this.getFieldLabel().setLabelForComponentId(this.getMessage().getId());
86 }
87 else{
88
89 this.getFieldLabel().setLabelForComponentId(this.getMessage().getId() + UifConstants.IdSuffixes.SPAN);
90 }
91 }
92 }
93
94
95
96
97
98
99 @BeanTagAttribute(name="messageText")
100 public void setMessageText(String messageText) {
101 if (message != null) {
102 message.setMessageText(messageText);
103 }
104 }
105
106
107
108
109
110
111 @BeanTagAttribute(name="inlineComponents")
112 public void setInlineComponents(List<Component> inlineComponents) {
113 if (message != null) {
114 message.setInlineComponents(inlineComponents);
115 }
116 }
117
118
119
120
121
122
123 @BeanTagAttribute(name="messageComponentStructure")
124 public void setMessageComponentStructure(List<Component> messageComponentStructure) {
125 if (message != null) {
126 message.setMessageComponentStructure(messageComponentStructure);
127 }
128 }
129
130
131
132
133
134
135 @BeanTagAttribute(name="message",type= BeanTagAttribute.AttributeType.SINGLEBEAN)
136 public Message getMessage() {
137 return message;
138 }
139
140
141
142
143
144
145 public void setMessage(Message message) {
146 this.message = message;
147 }
148
149
150
151
152 @Override
153 public void completeValidation(ValidationTrace tracer){
154 tracer.addBean(this);
155
156
157 if(getMessage()==null){
158 if(Validator.checkExpressions(this, "message")){
159 String currentValues [] = {"message ="+getMessage()};
160 tracer.createWarning("Message should not be null",currentValues);
161 }
162 }
163
164
165 if(getLabel()==null){
166 if(Validator.checkExpressions(this, "label")){
167 String currentValues [] = {"label ="+getLabel(),"Message ="+getMessage()};
168 tracer.createWarning("Label is null, message should be used instead",currentValues);
169 }
170 }
171
172 super.completeValidation(tracer.getCopy());
173 }
174
175
176
177
178 @Override
179 protected <T> void copyProperties(T component) {
180 super.copyProperties(component);
181 MessageField messageFieldCopy = (MessageField) component;
182
183 if (this.message != null) {
184 messageFieldCopy.setMessage((Message)this.message.copy());
185 }
186 }
187 }