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.apache.myfaces.tobago.event.PageActionEvent;
021 import org.apache.myfaces.tobago.event.PageAction;
022 import org.apache.myfaces.tobago.event.PageActionUtil;
023 import org.apache.myfaces.tobago.component.UIData;
024 import org.apache.myfaces.tobago.component.ComponentUtil;
025 import static org.apache.myfaces.tobago.TobagoConstants.SUBCOMPONENT_SEP;
026 import org.apache.commons.logging.Log;
027 import org.apache.commons.logging.LogFactory;
028
029 import javax.faces.context.FacesContext;
030 import javax.faces.component.UIComponent;
031 import java.util.Map;
032
033 /*
034 * Date: 24.04.2006
035 * Time: 22:02:49
036 */
037
038 //TODO move this back in the decode or SheetCommandRenderer
039 public class SheetUtils {
040 private static final Log LOG = LogFactory.getLog(SheetUtils.class);
041
042 public static void decode(FacesContext facesContext, UIComponent component) {
043 String actionId = ComponentUtil.findPage(facesContext, component).getActionId();
044 String clientId = component.getClientId(facesContext);
045 if (LOG.isDebugEnabled()) {
046 LOG.debug("actionId = '" + actionId + "'");
047 LOG.debug("clientId = '" + clientId + "'");
048 }
049 if (actionId != null && actionId.equals(clientId)) {
050
051 PageAction action;
052 try {
053 action = PageActionUtil.parse(component.getId());
054 if (action == null) {
055 LOG.error("Illegal value for PageAction :" + component.getId());
056 return;
057 }
058 } catch (Exception e) {
059 LOG.error("Illegal value for PageAction :" + component.getId());
060 return;
061 }
062 PageActionEvent event = new PageActionEvent((UIData) component.getParent(), action);
063
064 switch (action) {
065 case TO_PAGE:
066 case TO_ROW:
067 Map map = facesContext.getExternalContext().getRequestParameterMap();
068 Object value = map.get(clientId + SUBCOMPONENT_SEP + "value");
069 try {
070 event.setValue(Integer.parseInt((String) value));
071 } catch (Exception e) {
072 LOG.error("Can't parse value for action " + action.name() + ": " + value);
073 }
074 break;
075 default:
076 // nothing more to do
077 }
078 component.queueEvent(event);
079 }
080 }
081 }