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