001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied. See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019
020 package org.apache.myfaces.tobago.renderkit;
021
022 import org.apache.commons.lang.StringUtils;
023 import org.apache.commons.logging.Log;
024 import org.apache.commons.logging.LogFactory;
025 import org.apache.myfaces.tobago.TobagoConstants;
026 import org.apache.myfaces.tobago.component.ComponentUtil;
027
028 import javax.faces.component.UIComponent;
029 import javax.faces.component.UIInput;
030 import javax.faces.context.FacesContext;
031 import java.util.Map;
032
033 public class InputRendererBase extends LayoutableRendererBase {
034
035 private static final Log LOG = LogFactory.getLog(InputRendererBase.class);
036
037 public void decode(FacesContext context, UIComponent component) {
038 UIInput uiInput;
039 if (component instanceof UIInput) {
040 uiInput = (UIInput) component;
041 } else {
042 return; // no decoding required
043 }
044
045 if (ComponentUtil.isOutputOnly(component)) {
046 return;
047 }
048
049 String clientId = component.getClientId(context);
050
051 Map requestParameterMap = context.getExternalContext()
052 .getRequestParameterMap();
053 if (requestParameterMap.containsKey(clientId)) {
054 String newValue = (String) requestParameterMap.get(clientId);
055 if (LOG.isDebugEnabled()) {
056 final boolean password = ComponentUtil.getBooleanAttribute(component, TobagoConstants.ATTR_PASSWORD);
057 LOG.debug("clientId = '" + clientId + "'");
058 LOG.debug("requestParameterMap.get(clientId) = '"
059 + (password ? StringUtils.leftPad("", newValue.length(), '*') : newValue) + "'");
060 }
061 uiInput.setSubmittedValue(newValue);
062 }
063 }
064
065 public int getLabelWidth(FacesContext facesContext, UIComponent component) {
066 return getConfiguredValue(facesContext, component, "labelWidth");
067 }
068
069 }
070