1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.myfaces.tobago.internal.util;
21
22 import org.apache.myfaces.tobago.event.PageAction;
23 import org.apache.myfaces.tobago.event.PageActionEvent;
24 import org.apache.myfaces.tobago.util.ComponentUtils;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27
28 import javax.faces.component.UIComponent;
29 import javax.faces.context.FacesContext;
30 import java.util.Map;
31
32
33 public class PagingUtils {
34
35 private static final Logger LOG = LoggerFactory.getLogger(PagingUtils.class);
36
37 public static void decode(FacesContext facesContext, UIComponent component) {
38 String actionId = FacesContextUtils.getActionId(facesContext);
39 String clientId = component.getClientId(facesContext);
40 if (LOG.isDebugEnabled()) {
41 LOG.debug("actionId = '" + actionId + "'");
42 LOG.debug("clientId = '" + clientId + "'");
43 }
44 if (actionId != null && actionId.equals(clientId)) {
45
46 PageAction action;
47 try {
48 action = PageAction.parse(component.getId());
49 } catch (Exception e) {
50 LOG.error("Illegal value for PageAction :" + component.getId());
51 return;
52 }
53 PageActionEvent event = new PageActionEvent(component.getParent(), action);
54
55 switch (action) {
56 case TO_PAGE:
57 case TO_ROW:
58 Map map = facesContext.getExternalContext().getRequestParameterMap();
59 Object value = map.get(clientId + ComponentUtils.SUB_SEPARATOR + "value");
60 try {
61 event.setValue(Integer.parseInt((String) value));
62 } catch (NumberFormatException e) {
63 LOG.error("Can't parse integer value for action " + action.name() + ": " + value);
64 }
65 break;
66 default:
67
68 }
69 component.queueEvent(event);
70 }
71 }
72 }