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.validator;
21
22 import org.apache.myfaces.tobago.util.ComponentUtils;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25
26 import javax.faces.component.UIComponent;
27 import javax.faces.context.FacesContext;
28 import javax.faces.event.AbortProcessingException;
29 import javax.faces.event.ActionEvent;
30 import javax.faces.event.ActionListener;
31 import javax.faces.event.PhaseId;
32 import java.util.StringTokenizer;
33
34 public class ClearValidatorsActionListener implements ActionListener {
35
36 private static final Logger LOG = LoggerFactory.getLogger(ClearValidatorsActionListener.class);
37
38 public PhaseId getPhaseId() {
39 return PhaseId.APPLY_REQUEST_VALUES;
40 }
41
42 public void processAction(ActionEvent actionEvent) throws AbortProcessingException {
43 if (LOG.isDebugEnabled()) {
44 LOG.debug("actionEvent = '" + actionEvent + "'");
45 }
46 UIComponent source = actionEvent.getComponent();
47 String clearValidatorsFieldIds
48 = (String) ComponentUtils.findParameter(source, "clearValidatorsFieldIds");
49
50 if (LOG.isDebugEnabled()) {
51 LOG.debug("clearValidatorsFieldIds = '" + clearValidatorsFieldIds + "'");
52 }
53
54
55
56 for (StringTokenizer tokenizer
57 = new StringTokenizer(clearValidatorsFieldIds, ",");
58 tokenizer.hasMoreTokens();) {
59 String clearValidatorsFieldId = tokenizer.nextToken();
60
61 UIComponent component = source.findComponent(clearValidatorsFieldId);
62 if (LOG.isDebugEnabled()) {
63 LOG.debug("component = '" + component + "'");
64 }
65
66 if (component == null) {
67 if (LOG.isDebugEnabled()) {
68 LOG.debug("Component not found locally, asking the tree.");
69 }
70 FacesContext facesContext = FacesContext.getCurrentInstance();
71 component = facesContext.getViewRoot().findComponent(clearValidatorsFieldId);
72 }
73
74 if (component == null) {
75 LOG.warn("Component not found.");
76 } else {
77
78 LOG.error("NO LONGER AVAILABLE: component.clearValidators();");
79 }
80 }
81 }
82
83 }