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