001/** 002 * Copyright 2005-2016 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.krad.uif.view; 017 018import org.kuali.rice.krad.datadictionary.parse.BeanTag; 019import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute; 020import org.kuali.rice.krad.uif.component.Component; 021import org.kuali.rice.krad.uif.element.Message; 022import org.kuali.rice.krad.uif.util.ComponentFactory; 023 024import java.util.List; 025 026/** 027 * View that presents a message to the user (for example an application error message) 028 * 029 * @author Kuali Rice Team (rice.collab@kuali.org) 030 */ 031@BeanTag(name = "messageView", parent="Uif-MessageView") 032public class MessageView extends FormView { 033 private static final long serialVersionUID = 5578210247236389466L; 034 035 private Message message; 036 037 public MessageView() { 038 super(); 039 040 super.setSinglePageView(true); 041 } 042 043 /** 044 * The following initialization is performed: 045 * 046 * <ul> 047 * <li>Set the message text onto the message component and add to the page items</li> 048 * </ul> 049 * 050 * {@inheritDoc} 051 */ 052 public void performInitialization(Object model) { 053 super.performInitialization(model); 054 055 List<Component> newItems = (List<Component>) getPage().getItems(); 056 newItems.add(message); 057 getPage().setItems(newItems); 058 } 059 060 /** 061 * Message component that will be used to display the message (used for styling and so on) 062 * 063 * @return Message component instance 064 */ 065 @BeanTagAttribute(type = BeanTagAttribute.AttributeType.DIRECTORBYTYPE) 066 public Message getMessage() { 067 return message; 068 } 069 070 /** 071 * Setter for the message component 072 * 073 * @param message 074 */ 075 public void setMessage(Message message) { 076 this.message = message; 077 } 078 079 /** 080 * Message text to display in the message view. 081 * 082 * @return message text as string 083 */ 084 @BeanTagAttribute 085 public String getMessageText() { 086 if (this.message != null) { 087 return this.message.getMessageText(); 088 } 089 090 return null; 091 } 092 093 /** 094 * @see MessageView#getMessageText() 095 */ 096 public void setMessageText(String messageText) { 097 if (this.message == null) { 098 this.message = ComponentFactory.getMessage(); 099 } 100 101 this.message.setMessageText(messageText); 102 } 103}