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 static org.apache.myfaces.tobago.TobagoConstants.SUBCOMPONENT_SEP;
026    import org.apache.myfaces.tobago.component.UIPage;
027    import org.apache.myfaces.tobago.layout.Box;
028    
029    import javax.faces.component.UIComponent;
030    import javax.faces.context.FacesContext;
031    
032    public class PageRendererBase extends LayoutableRendererBase {
033    
034      private static final Log LOG = LogFactory.getLog(PageRendererBase.class);
035    
036      public void decode(FacesContext facesContext, UIComponent component) {
037        if (component instanceof UIPage) {
038          UIPage page = (UIPage) component;
039    
040    
041          String name = page.getClientId(facesContext) + SUBCOMPONENT_SEP + "form-action";
042          String newActionId = (String) facesContext.getExternalContext().getRequestParameterMap().get(name);
043          if (LOG.isDebugEnabled()) {
044            LOG.debug("action = " + newActionId);
045          }
046          page.setActionId(newActionId);
047    
048          try {
049            String actionPositionName = page.getClientId(facesContext) + SUBCOMPONENT_SEP + "action-position";
050            String actionPositionString = (String)
051                facesContext.getExternalContext().getRequestParameterMap().get(actionPositionName);
052            if (LOG.isDebugEnabled()) {
053              LOG.debug("actionPosition='" + actionPositionString + "'");
054            }
055            if (StringUtils.isNotEmpty(actionPositionString)) {
056              Box actionPosition = new Box(actionPositionString);
057              page.setActionPosition(actionPosition);
058            } else {
059              page.setActionPosition(null);
060            }
061          } catch (Exception e) {
062            LOG.warn("Can't analyse parameter for action-position", e);
063          }
064    
065        }
066      }
067    }
068