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: import javax.faces.model.*;
036:
037: public class UISelectItems extends UIComponentBase {
038: public static final String COMPONENT_FAMILY = "javax.faces.SelectItems";
039: public static final String COMPONENT_TYPE = "javax.faces.SelectItems";
040:
041: private Object _value;
042: private ValueExpression _valueExpr;
043:
044: public UISelectItems() {
045: setRendererType(null);
046: }
047:
048: /**
049: * Returns the component family, used to select the renderer.
050: */
051: public String getFamily() {
052: return COMPONENT_FAMILY;
053: }
054:
055: //
056: // properties
057: //
058:
059: public Object getValue() {
060: if (_value != null)
061: return _value;
062: else if (_valueExpr != null)
063: return Util.eval(_valueExpr, getFacesContext());
064: else
065: return null;
066: }
067:
068: public void setValue(Object value) {
069: _value = value;
070: }
071:
072: /**
073: * Returns the value expression with the given name.
074: */
075: @Override
076: public ValueExpression getValueExpression(String name) {
077: if ("value".equals(name))
078: return _valueExpr;
079: else
080: return super .getValueExpression(name);
081: }
082:
083: /**
084: * Sets the value expression with the given name.
085: */
086: @Override
087: public void setValueExpression(String name, ValueExpression expr) {
088: if ("value".equals(name)) {
089: if (expr != null && expr.isLiteralText()) {
090: _value = expr.getValue(null);
091: return;
092: } else
093: _valueExpr = expr;
094: }
095:
096: super .setValueExpression(name, expr);
097: }
098:
099: //
100: // state
101: //
102:
103: public Object saveState(FacesContext context) {
104: return new Object[] { super .saveState(context), _value };
105: }
106:
107: public void restoreState(FacesContext context, Object value) {
108: Object[] state = (Object[]) value;
109:
110: super .restoreState(context, state[0]);
111:
112: _value = state[1];
113: }
114: }
|