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.html;
018:
019: import org.apache.cocoon.faces.FacesUtils;
020: import org.apache.cocoon.faces.taglib.UIComponentTag;
021: import org.apache.commons.lang.BooleanUtils;
022:
023: import javax.faces.FacesException;
024: import javax.faces.component.UIComponent;
025: import javax.faces.component.UIInput;
026: import javax.faces.context.FacesContext;
027: import javax.faces.el.MethodBinding;
028: import javax.faces.event.ValueChangeEvent;
029:
030: /**
031: * @version CVS $Id: InputHiddenTag.java 433543 2006-08-22 06:22:54Z crossley $
032: */
033: public class InputHiddenTag extends UIComponentTag {
034:
035: private String converter;
036: private String immediate;
037: private String required;
038: private String validator;
039: private String value;
040: private String valueChangeListener;
041:
042: public void setConverter(String converter) {
043: this .converter = converter;
044: }
045:
046: public void setImmediate(String immediate) {
047: this .immediate = immediate;
048: }
049:
050: public void setRequired(String required) {
051: this .required = required;
052: }
053:
054: public void setValidator(String validator) {
055: this .validator = validator;
056: }
057:
058: public void setValue(String value) {
059: this .value = value;
060: }
061:
062: public void setValueChangeListener(String valueChangeListener) {
063: this .valueChangeListener = valueChangeListener;
064: }
065:
066: public String getRendererType() {
067: return "javax.faces.Hidden";
068: }
069:
070: public String getComponentType() {
071: return "javax.faces.HtmlInputHidden";
072: }
073:
074: protected void setProperties(UIComponent component) {
075: super .setProperties(component);
076:
077: UIInput input = null;
078: try {
079: input = (UIInput) component;
080: } catch (ClassCastException cce) {
081: throw new FacesException("Tag <" + getClass().getName()
082: + "> expected UIInput. " + "Got <"
083: + component.getClass().getName() + ">");
084: }
085:
086: if (converter != null) {
087: if (FacesUtils.isExpression(converter)) {
088: input.setValueBinding("converter",
089: createValueBinding(converter));
090: } else {
091: input.setConverter(getApplication().createConverter(
092: converter));
093: }
094: }
095:
096: if (immediate != null) {
097: if (FacesUtils.isExpression(immediate)) {
098: input.setValueBinding("immediate",
099: createValueBinding(immediate));
100: } else {
101: input.setImmediate(BooleanUtils.toBoolean(immediate));
102: }
103: }
104:
105: if (required != null) {
106: if (FacesUtils.isExpression(required)) {
107: input.setValueBinding("required",
108: createValueBinding(required));
109: } else {
110: input.setRequired(BooleanUtils.toBoolean(required));
111: }
112: }
113:
114: if (validator != null) {
115: if (FacesUtils.isExpression(validator)) {
116: MethodBinding vb = getApplication()
117: .createMethodBinding(
118: validator,
119: new Class[] { FacesContext.class,
120: UIComponent.class, Object.class });
121: input.setValidator(vb);
122: } else {
123: throw new FacesException("Tag <" + getClass().getName()
124: + "> validator must be an expression. "
125: + "Got <" + validator + ">");
126: }
127: }
128:
129: if (value != null) {
130: if (FacesUtils.isExpression(value)) {
131: input.setValueBinding("value",
132: createValueBinding(value));
133: } else {
134: input.setValue(value);
135: }
136: }
137:
138: if (valueChangeListener != null) {
139: if (FacesUtils.isExpression(valueChangeListener)) {
140: MethodBinding vb = getApplication()
141: .createMethodBinding(valueChangeListener,
142: new Class[] { ValueChangeEvent.class });
143: input.setValueChangeListener(vb);
144: } else {
145: throw new FacesException(
146: "Tag <"
147: + getClass().getName()
148: + "> valueChangeListener must be an expression. "
149: + "Got <" + valueChangeListener + ">");
150: }
151: }
152: }
153:
154: public void recycle() {
155: super.recycle();
156: converter = null;
157: immediate = null;
158: required = null;
159: validator = null;
160: value = null;
161: valueChangeListener = null;
162: }
163: }
|