View Javadoc
1   /**
2    * Copyright 2005-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.uif.view;
17  
18  import org.kuali.rice.krad.datadictionary.parse.BeanTag;
19  import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
20  import org.kuali.rice.krad.uif.component.Component;
21  import org.kuali.rice.krad.uif.element.Message;
22  import org.kuali.rice.krad.uif.util.ComponentFactory;
23  
24  import java.util.List;
25  
26  /**
27   * View that presents a message to the user (for example an application error message)
28   *
29   * @author Kuali Rice Team (rice.collab@kuali.org)
30   */
31  @BeanTag(name = "messageView", parent="Uif-MessageView")
32  public class MessageView extends FormView {
33      private static final long serialVersionUID = 5578210247236389466L;
34  
35      private Message message;
36  
37      public MessageView() {
38          super();
39  
40          super.setSinglePageView(true);
41      }
42  
43      /**
44       * The following initialization is performed:
45       *
46       * <ul>
47       * <li>Set the message text onto the message component and add to the page items</li>
48       * </ul>
49       *
50       * {@inheritDoc}
51       */
52      public void performInitialization(Object model) {
53          super.performInitialization(model);
54  
55          List<Component> newItems = (List<Component>) getPage().getItems();
56          newItems.add(message);
57          getPage().setItems(newItems);
58      }
59  
60      /**
61       * Message component that will be used to display the message (used for styling and so on)
62       *
63       * @return Message component instance
64       */
65      @BeanTagAttribute(type = BeanTagAttribute.AttributeType.DIRECTORBYTYPE)
66      public Message getMessage() {
67          return message;
68      }
69  
70      /**
71       * Setter for the message component
72       *
73       * @param message
74       */
75      public void setMessage(Message message) {
76          this.message = message;
77      }
78  
79      /**
80       * Message text to display in the message view.
81       *
82       * @return message text as string
83       */
84      @BeanTagAttribute
85      public String getMessageText() {
86          if (this.message != null) {
87              return this.message.getMessageText();
88          }
89  
90          return null;
91      }
92  
93      /**
94       * @see MessageView#getMessageText()
95       */
96      public void setMessageText(String messageText) {
97          if (this.message == null) {
98              this.message = ComponentFactory.getMessage();
99          }
100 
101         this.message.setMessageText(messageText);
102     }
103 }