1 /* 2 * $Id: UIMessage.java,v 1.20 2007/10/18 17:05:23 rlubke Exp $ 3 */ 4 5 /* 6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 7 * 8 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. 9 * 10 * The contents of this file are subject to the terms of either the GNU 11 * General Public License Version 2 only ("GPL") or the Common Development 12 * and Distribution License("CDDL") (collectively, the "License"). You 13 * may not use this file except in compliance with the License. You can obtain 14 * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html 15 * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific 16 * language governing permissions and limitations under the License. 17 * 18 * When distributing the software, include this License Header Notice in each 19 * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt. 20 * Sun designates this particular file as subject to the "Classpath" exception 21 * as provided by Sun in the GPL Version 2 section of the License file that 22 * accompanied this code. If applicable, add the following below the License 23 * Header, with the fields enclosed by brackets [] replaced by your own 24 * identifying information: "Portions Copyrighted [year] 25 * [name of copyright owner]" 26 * 27 * Contributor(s): 28 * 29 * If you wish your version of this file to be governed by only the CDDL or 30 * only the GPL Version 2, indicate your decision by adding "[Contributor] 31 * elects to include this software in this distribution under the [CDDL or GPL 32 * Version 2] license." If you don't indicate a single choice of license, a 33 * recipient has the option to distribute your version of this file under 34 * either the CDDL, the GPL Version 2 or to extend the choice of license to 35 * its licensees as provided above. However, if you add GPL Version 2 code 36 * and therefore, elected the GPL Version 2 license, then the option applies 37 * only if the new code is made subject to such option by the copyright 38 * holder. 39 */ 40 41 package javax.faces.component; 42 43 import javax.faces.context.FacesContext; 44 45 46 /** 47 * <p>This component is responsible for displaying messages for a specific 48 * {@link UIComponent}, identified by a <code>clientId</code>. The component 49 * obtains the messages from the {@link FacesContext}.</p> 50 * 51 * <p>By default, the <code>rendererType</code> property must be set to 52 * "<code>javax.faces.Message</code>". This value can be changed by 53 * calling the <code>setRendererType()</code> method.</p> 54 55 * 56 */ 57 58 public class UIMessage extends UIComponentBase { 59 60 61 // ------------------------------------------------------ Manifest Constants 62 63 64 /** 65 * <p>The standard component type for this component.</p> 66 */ 67 public static final String COMPONENT_TYPE = "javax.faces.Message"; 68 69 70 /** 71 * <p>The standard component family for this component.</p> 72 */ 73 public static final String COMPONENT_FAMILY = "javax.faces.Message"; 74 75 76 enum PropertyKeys { 77 78 forValue("for"), 79 showDetail, 80 showSummary, 81 redisplay; 82 83 String toString; 84 85 PropertyKeys(String toString) { 86 this.toString = toString; 87 } 88 89 PropertyKeys() { 90 } 91 92 public String toString() { 93 return ((this.toString != null) ? this.toString : super.toString()); 94 } 95 96 } 97 98 99 // ------------------------------------------------------------ Constructors 100 101 102 /** 103 * <p>Create a new {@link UIMessage} instance with default property 104 * values.</p> 105 */ 106 public UIMessage() { 107 108 super(); 109 setRendererType("javax.faces.Message"); 110 111 } 112 113 114 // -------------------------------------------------------------- Properties 115 116 117 public String getFamily() { 118 119 return (COMPONENT_FAMILY); 120 121 } 122 123 124 /** 125 * <p>Return the client identifier of the component for which 126 * this component represents associated message(s) (if any).</p> 127 */ 128 public String getFor() { 129 130 return (String) getStateHelper().eval(PropertyKeys.forValue); 131 132 } 133 134 135 /** 136 * <p>Set the client identifier of the component for which this 137 * component represents associated message(s) (if any). This 138 * property must be set before the message is displayed.</p> 139 * 140 * @param newFor The new client id 141 */ 142 public void setFor(String newFor) { 143 144 getStateHelper().put(PropertyKeys.forValue, newFor); 145 146 } 147 148 149 /** 150 * <p>Return the flag indicating whether the <code>detail</code> 151 * property of the associated message(s) should be displayed. 152 * Defaults to <code>true</code>.</p> 153 */ 154 public boolean isShowDetail() { 155 156 return (Boolean) getStateHelper().eval(PropertyKeys.showDetail, true); 157 158 } 159 160 161 /** 162 * <p>Set the flag indicating whether the <code>detail</code> property 163 * of the associated message(s) should be displayed.</p> 164 * 165 * @param showDetail The new flag 166 */ 167 public void setShowDetail(boolean showDetail) { 168 169 getStateHelper().put(PropertyKeys.showDetail, showDetail); 170 171 } 172 173 174 /** 175 * <p>Return the flag indicating whether the <code>summary</code> 176 * property of the associated message(s) should be displayed. 177 * Defaults to <code>false</code>.</p> 178 */ 179 public boolean isShowSummary() { 180 181 return (Boolean) getStateHelper().eval(PropertyKeys.showSummary, false); 182 183 } 184 185 186 /** 187 * <p>Set the flag indicating whether the <code>summary</code> property 188 * of the associated message(s) should be displayed.</p> 189 * 190 * @param showSummary The new flag value 191 */ 192 public void setShowSummary(boolean showSummary) { 193 194 getStateHelper().put(PropertyKeys.showSummary, showSummary); 195 196 } 197 198 199 /** 200 * @return <code>true</code> if this <code>UIMessage</code> instance should 201 * redisplay {@link javax.faces.application.FacesMessage}s that have already been handled, 202 * otherwise returns <code>false</code>. By default this method will 203 * always return <code>true</code> if {@link #setRedisplay(boolean)} has 204 * not been called. 205 * 206 * @since 2.0 207 */ 208 public boolean isRedisplay() { 209 210 return (Boolean) getStateHelper().eval(PropertyKeys.redisplay, true); 211 212 } 213 214 215 /** 216 * <p>Set the flag indicating whether the <code>detail</code> property 217 * of the associated message(s) should be displayed.</p> 218 * 219 * @param redisplay flag indicating whether previously handled messages 220 * are redisplayed or not 221 * 222 * @since 2.0 223 */ 224 public void setRedisplay(boolean redisplay) { 225 226 getStateHelper().put(PropertyKeys.redisplay, redisplay); 227 228 } 229 230 231 }