View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.tobago.renderkit.html.scarborough.standard.tag;
21  
22  import org.apache.myfaces.tobago.event.PageAction;
23  import org.apache.myfaces.tobago.event.PageActionEvent;
24  import org.apache.myfaces.tobago.internal.util.FacesContextUtils;
25  import org.apache.myfaces.tobago.util.ComponentUtils;
26  import org.slf4j.Logger;
27  import org.slf4j.LoggerFactory;
28  
29  import javax.faces.component.UIComponent;
30  import javax.faces.context.FacesContext;
31  import java.util.Map;
32  
33  public class SheetPageCommandRenderer extends LinkRenderer {
34  
35    private static final Logger LOG = LoggerFactory.getLogger(SheetPageCommandRenderer.class);
36  
37    @Override
38    public void decode(FacesContext facesContext, UIComponent component) {
39      String actionId = FacesContextUtils.getActionId(facesContext);
40      String clientId = component.getClientId(facesContext);
41      if (LOG.isDebugEnabled()) {
42        LOG.debug("actionId = '" + actionId + "'");
43        LOG.debug("clientId = '" + clientId + "'");
44      }
45      if (actionId != null && actionId.equals(clientId)) {
46  
47        PageAction action;
48        try {
49          action = PageAction.parse(component.getId());
50        } catch (Exception e) {
51          LOG.error("Illegal value for PageAction :" + component.getId());
52          return;
53        }
54        PageActionEvent event = new PageActionEvent(component.getParent(), action);
55  
56        switch (action) {
57          case TO_PAGE:
58          case TO_ROW:
59            Map map = facesContext.getExternalContext().getRequestParameterMap();
60            Object value = map.get(clientId + ComponentUtils.SUB_SEPARATOR + "value");
61            try {
62              event.setValue(Integer.parseInt((String) value));
63            } catch (NumberFormatException e) {
64              LOG.error("Can't parse integer value for action " + action.name() + ": " + value);
65            }
66            break;
67          default:
68            // nothing more to do
69        }
70        component.queueEvent(event);
71      }
72    }
73  }