View Javadoc

1   /**
2    * Copyright 2005-2013 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.apache.commons.lang.StringUtils;
19  import org.kuali.rice.krad.uif.component.Component;
20  import org.kuali.rice.krad.uif.element.Message;
21  
22  import java.util.List;
23  
24  /**
25   * View that presents a message to the user (for example an application error message)
26   *
27   * @author Kuali Rice Team (rice.collab@kuali.org)
28   */
29  public class MessageView extends FormView {
30      private static final long serialVersionUID = 5578210247236389466L;
31  
32      private String messageText;
33      private Message message;
34  
35      public MessageView() {
36          super();
37  
38          super.setSinglePageView(true);
39      }
40  
41      /**
42       * The following initialization is performed:
43       *
44       * <ul>
45       * <li>Set the message text onto the message component and add to the page items</li>
46       * </ul>
47       *
48       * @see org.kuali.rice.krad.uif.container.ContainerBase#performInitialization(View, java.lang.Object)
49       */
50      public void performInitialization(View view, Object model) {
51          super.performInitialization(view, model);
52  
53          if (StringUtils.isNotBlank(messageText) && StringUtils.isBlank(message.getMessageText())) {
54              message.setMessageText(messageText);
55          }
56  
57          List<Component> newItems = (List<Component>) getPage().getItems();
58          newItems.add(message);
59          getPage().setItems(newItems);
60      }
61  
62      /**
63       * @see org.kuali.rice.krad.uif.component.ComponentBase#getComponentsForLifecycle()
64       */
65      @Override
66      public List<Component> getComponentsForLifecycle() {
67          List<Component> components = super.getComponentsForLifecycle();
68  
69          components.add(message);
70  
71          return components;
72      }
73  
74      /**
75       * Test for the message to display
76       *
77       * @return String message text
78       */
79      public String getMessageText() {
80          return messageText;
81      }
82  
83      /**
84       * Setter for the views message text
85       *
86       * @param messageText
87       */
88      public void setMessageText(String messageText) {
89          this.messageText = messageText;
90      }
91  
92      /**
93       * Message component that will be used to display the message (used for styling and so on)
94       *
95       * @return Message component instance
96       */
97      public Message getMessage() {
98          return message;
99      }
100 
101     /**
102      * Setter for the message component
103      *
104      * @param message
105      */
106     public void setMessage(Message message) {
107         this.message = message;
108     }
109 }