001: /*
002: * Version: MPL 1.1/GPL 2.0/LGPL 2.1
003: *
004: * "The contents of this file are subject to the Mozilla Public License
005: * Version 1.1 (the "License"); you may not use this file except in
006: * compliance with the License. You may obtain a copy of the License at
007: * http://www.mozilla.org/MPL/
008: *
009: * Software distributed under the License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
011: * License for the specific language governing rights and limitations under
012: * the License.
013: *
014: * The Original Code is ICEfaces 1.5 open source software code, released
015: * November 5, 2006. The Initial Developer of the Original Code is ICEsoft
016: * Technologies Canada, Corp. Portions created by ICEsoft are Copyright (C)
017: * 2004-2006 ICEsoft Technologies Canada, Corp. All Rights Reserved.
018: *
019: * Contributor(s): _____________________.
020: *
021: * Alternatively, the contents of this file may be used under the terms of
022: * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"
023: * License), in which case the provisions of the LGPL License are
024: * applicable instead of those above. If you wish to allow use of your
025: * version of this file only under the terms of the LGPL License and not to
026: * allow others to use your version of this file under the MPL, indicate
027: * your decision by deleting the provisions above and replace them with
028: * the notice and other provisions required by the LGPL License. If you do
029: * not delete the provisions above, a recipient may use your version of
030: * this file under either the MPL or the LGPL License."
031: *
032: */
033:
034: package com.icesoft.faces.renderkit.dom_html_basic;
035:
036: import javax.faces.component.UIComponent;
037: import javax.faces.component.UIInput;
038: import javax.faces.component.ValueHolder;
039: import javax.faces.context.FacesContext;
040: import javax.faces.convert.Converter;
041: import javax.faces.convert.ConverterException;
042: import javax.faces.el.ValueBinding;
043:
044: public abstract class DomBasicInputRenderer extends DomBasicRenderer {
045:
046: /**
047: * Set the submittedValue parameter to the UIComponent instance if and only
048: * if the UIComponent is a subclass of UIInput
049: */
050: public void setSubmittedValue(UIComponent uiComponent,
051: Object submittedValue) {
052: if (uiComponent instanceof UIInput) {
053: ((UIInput) uiComponent).setSubmittedValue(submittedValue);
054: }
055: }
056:
057: Object getValue(UIComponent uiComponent) {
058: Object value = null;
059: if (uiComponent instanceof ValueHolder) {
060: value = ((ValueHolder) uiComponent).getValue();
061: }
062: return value;
063: }
064:
065: /**
066: * Return the converted submittedValue. If a converter is registered with
067: * the component then use that converter. Otherwise get the default
068: * converter corresponding to the type of the value binding. If no converter
069: * is found then return the submittedValue unchanged.
070: *
071: * @param facesContext the current FacesContext
072: * @param uiComponent the uiComponent whose value will be converted.
073: * @param submittedValue the submittedValue to be submitted
074: */
075:
076: public Object getConvertedValue(FacesContext facesContext,
077: UIComponent uiComponent, Object submittedValue)
078: throws ConverterException {
079:
080: // get the converter (if any) registered with this component
081: Converter converter = null;
082: if (uiComponent instanceof ValueHolder) {
083: converter = ((ValueHolder) uiComponent).getConverter();
084: }
085: // if we didn't find a converter specifically registered with the component
086: // then get the default converter for the type of the value binding,
087: // if it exists
088: ValueBinding valueBinding = uiComponent
089: .getValueBinding("value");
090: if (converter == null && valueBinding != null) {
091: Class valueBindingClass = valueBinding
092: .getType(facesContext);
093: if (valueBindingClass != null) {
094: converter = facesContext.getApplication()
095: .createConverter(valueBindingClass);
096: }
097: }
098:
099: if (converter != null) {
100: return converter.getAsObject(facesContext, uiComponent,
101: (String) submittedValue);
102: } else if (submittedValue != null) {
103: return (String) submittedValue;
104: } else {
105: return null;
106: }
107: }
108: }
|