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