001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.faces.taglib;
018:
019: import org.apache.cocoon.faces.FacesUtils;
020: import org.apache.commons.lang.BooleanUtils;
021:
022: import javax.faces.FacesException;
023: import javax.faces.component.UIComponent;
024: import javax.faces.component.UISelectItem;
025:
026: /**
027: * @version CVS $Id: SelectItemTag.java 433543 2006-08-22 06:22:54Z crossley $
028: */
029: public class SelectItemTag extends UIComponentTag {
030:
031: protected String value;
032: protected String itemValue;
033: protected String itemLabel;
034: protected String itemDescription;
035: protected String itemDisabled;
036:
037: public void setValue(String value) {
038: this .value = value;
039: }
040:
041: public void setItemValue(String itemValue) {
042: this .itemValue = itemValue;
043: }
044:
045: public void setItemLabel(String itemLabel) {
046: this .itemLabel = itemLabel;
047: }
048:
049: public void setItemDescription(String itemDescription) {
050: this .itemDescription = itemDescription;
051: }
052:
053: public void setItemDisabled(String itemDisabled) {
054: this .itemDisabled = itemDisabled;
055: }
056:
057: protected String getComponentType() {
058: return "javax.faces.SelectItem";
059: }
060:
061: protected String getRendererType() {
062: return null;
063: }
064:
065: protected void setProperties(UIComponent component) {
066: super .setProperties(component);
067:
068: UISelectItem selectItem;
069: try {
070: selectItem = (UISelectItem) component;
071: } catch (ClassCastException cce) {
072: throw new FacesException("Tag <" + getClass().getName()
073: + "> expected UISelectItem. " + "Got <"
074: + component.getClass().getName() + ">");
075: }
076:
077: if (value != null) {
078: if (FacesUtils.isExpression(value)) {
079: selectItem.setValueBinding("value",
080: createValueBinding(value));
081: } else {
082: selectItem.setValue(value);
083: }
084: }
085:
086: if (itemValue != null) {
087: if (FacesUtils.isExpression(itemValue)) {
088: selectItem.setValueBinding("itemValue",
089: createValueBinding(itemValue));
090: } else {
091: selectItem.setItemValue(itemValue);
092: }
093: }
094:
095: if (itemLabel != null) {
096: if (FacesUtils.isExpression(itemLabel)) {
097: selectItem.setValueBinding("itemLabel",
098: createValueBinding(itemLabel));
099: } else {
100: selectItem.setItemLabel(itemLabel);
101: }
102: }
103:
104: if (itemDescription != null) {
105: if (FacesUtils.isExpression(itemDescription)) {
106: selectItem.setValueBinding("itemDescription",
107: createValueBinding(itemDescription));
108: } else {
109: selectItem.setItemDescription(itemDescription);
110: }
111: }
112:
113: if (itemDisabled != null) {
114: if (FacesUtils.isExpression(itemDisabled)) {
115: selectItem.setValueBinding("itemDisabled",
116: createValueBinding(itemDisabled));
117: } else {
118: selectItem.setItemDisabled(BooleanUtils
119: .toBoolean(itemDisabled));
120: }
121: }
122: }
123:
124: public void recycle() {
125: super.recycle();
126: this.value = null;
127: this.itemValue = null;
128: this.itemLabel = null;
129: this.itemDescription = null;
130: this.itemDisabled = null;
131: }
132: }
|