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.validator.ErrorReport;
22 import org.kuali.rice.krad.datadictionary.validator.Validator;
23 import org.kuali.rice.krad.datadictionary.validator.ValidationTrace;
24 import org.kuali.rice.krad.uif.UifConstants;
25 import org.kuali.rice.krad.uif.component.Component;
26 import org.kuali.rice.krad.uif.container.Container;
27 import org.kuali.rice.krad.uif.element.Message;
28 import org.kuali.rice.krad.uif.view.View;
29
30 import java.util.ArrayList;
31 import java.util.List;
32
33
34
35
36
37
38
39
40
41
42
43 @BeanTag(name="messageField")
44 public class MessageField extends FieldBase {
45 private static final long serialVersionUID = -7045208136391722063L;
46
47 private Message message;
48
49 public MessageField() {
50 super();
51 }
52
53
54
55
56 @Override
57 public List<Component> getComponentsForLifecycle() {
58 List<Component> components = super.getComponentsForLifecycle();
59
60 components.add(message);
61
62 return components;
63 }
64
65
66
67
68
69
70
71
72 @Override
73 public void performFinalize(View view, Object model, Component parent) {
74 super.performFinalize(view, model, parent);
75
76
77 if(this.getFieldLabel() != null && this.getMessage() != null
78 && StringUtils.isNotBlank(this.getMessage().getId())){
79
80 if(this.getMessage().getMessageComponentStructure() != null
81 && !this.getMessage().getMessageComponentStructure().isEmpty()){
82
83 this.getFieldLabel().setLabelForComponentId(this.getMessage().getId());
84 }
85 else{
86
87 this.getFieldLabel().setLabelForComponentId(this.getMessage().getId() + UifConstants.IdSuffixes.SPAN);
88 }
89 }
90 }
91
92
93
94
95
96
97 @BeanTagAttribute(name="messageText")
98 public void setMessageText(String messageText) {
99 if (message != null) {
100 message.setMessageText(messageText);
101 }
102 }
103
104
105
106
107
108
109 @BeanTagAttribute(name="message",type= BeanTagAttribute.AttributeType.SINGLEBEAN)
110 public Message getMessage() {
111 return message;
112 }
113
114
115
116
117
118
119 public void setMessage(Message message) {
120 this.message = message;
121 }
122
123
124
125
126 @Override
127 public void completeValidation(ValidationTrace tracer){
128 tracer.addBean(this);
129
130
131 if(getMessage()==null){
132 if(Validator.checkExpressions(this, "message")){
133 String currentValues [] = {"message ="+getMessage()};
134 tracer.createWarning("Message should not be null",currentValues);
135 }
136 }
137
138
139 if(getLabel()==null){
140 if(Validator.checkExpressions(this, "label")){
141 String currentValues [] = {"label ="+getLabel(),"Message ="+getMessage()};
142 tracer.createWarning("Label is null, message should be used instead",currentValues);
143 }
144 }
145
146 super.completeValidation(tracer.getCopy());
147 }
148 }