001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License version 2
011: * as published by the Free Software Foundation.
012: *
013: * Resin Open Source is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
016: * of NON-INFRINGEMENT. See the GNU General Public License for more
017: * details.
018: *
019: * You should have received a copy of the GNU General Public License
020: * along with Resin Open Source; if not, write to the
021: *
022: * Free Software Foundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package javax.faces.component;
030:
031: import java.util.*;
032:
033: import javax.el.*;
034: import javax.faces.context.*;
035:
036: public class UIMessages extends UIComponentBase {
037: public static final String COMPONENT_FAMILY = "javax.faces.Messages";
038: public static final String COMPONENT_TYPE = "javax.faces.Messages";
039:
040: private Boolean _globalOnly;
041: private ValueExpression _globalOnlyExpr;
042:
043: private Boolean _showDetail;
044: private ValueExpression _showDetailExpr;
045:
046: private Boolean _showSummary;
047: private ValueExpression _showSummaryExpr;
048:
049: public UIMessages() {
050: setRendererType("javax.faces.Messages");
051: }
052:
053: /**
054: * Returns the component family, used to select the renderer.
055: */
056: public String getFamily() {
057: return COMPONENT_FAMILY;
058: }
059:
060: //
061: // properties
062: //
063:
064: public boolean isGlobalOnly() {
065: if (_globalOnly != null)
066: return _globalOnly;
067: else if (_globalOnlyExpr != null)
068: return Util.evalBoolean(_globalOnlyExpr, getFacesContext());
069: else
070: return false;
071: }
072:
073: public void setGlobalOnly(boolean value) {
074: _globalOnly = value;
075: }
076:
077: public boolean isShowDetail() {
078: if (_showDetail != null)
079: return _showDetail;
080: else if (_showDetailExpr != null)
081: return Util.evalBoolean(_showDetailExpr, getFacesContext());
082: else
083: return false;
084: }
085:
086: public void setShowDetail(boolean value) {
087: _showDetail = value;
088: }
089:
090: public boolean isShowSummary() {
091: if (_showSummary != null)
092: return _showSummary;
093: else if (_showSummaryExpr != null)
094: return Util
095: .evalBoolean(_showSummaryExpr, getFacesContext());
096: else
097: return true;
098: }
099:
100: public void setShowSummary(boolean value) {
101: _showSummary = value;
102: }
103:
104: /**
105: * Returns the value expression with the given name.
106: */
107: @Override
108: public ValueExpression getValueExpression(String name) {
109: if ("globalOnly".equals(name))
110: return _globalOnlyExpr;
111: else if ("showDetail".equals(name))
112: return _showDetailExpr;
113: else if ("showSummary".equals(name))
114: return _showSummaryExpr;
115: else
116: return super .getValueExpression(name);
117: }
118:
119: /**
120: * Sets the value expression with the given name.
121: */
122: @Override
123: public void setValueExpression(String name, ValueExpression expr) {
124: if ("globalOnly".equals(name)) {
125: if (expr != null && expr.isLiteralText()) {
126: _globalOnly = Util.booleanValueOf(expr.getValue(null));
127: return;
128: } else
129: _globalOnlyExpr = expr;
130: } else if ("showDetail".equals(name)) {
131: if (expr != null && expr.isLiteralText()) {
132: _showDetail = Util.booleanValueOf(expr.getValue(null));
133: return;
134: } else
135: _showDetailExpr = expr;
136: } else if ("showSummary".equals(name)) {
137: if (expr != null && expr.isLiteralText()) {
138: _showSummary = Util.booleanValueOf(expr.getValue(null));
139: return;
140: } else
141: _showSummaryExpr = expr;
142: }
143:
144: super .setValueExpression(name, expr);
145: }
146:
147: //
148: // state
149: //
150:
151: public Object saveState(FacesContext context) {
152: return new Object[] { super .saveState(context), _globalOnly,
153: _showDetail, _showSummary, };
154: }
155:
156: public void restoreState(FacesContext context, Object value) {
157: Object[] state = (Object[]) value;
158:
159: super .restoreState(context, state[0]);
160:
161: _globalOnly = (Boolean) state[1];
162: _showDetail = (Boolean) state[2];
163: _showSummary = (Boolean) state[3];
164: }
165: }
|