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.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      // FIXME: finding mechanism??? JSF ???
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) { // not found locally
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) { // not found 
75          LOG.warn("Component not found.");
76        } else {
77  //        component.clearValidators();
78          LOG.error("NO LONGER AVAILABLE: component.clearValidators();");
79        }
80      }
81    }
82  
83  }