001 package org.apache.myfaces.tobago.validator;
002
003 /*
004 * Licensed to the Apache Software Foundation (ASF) under one or more
005 * contributor license agreements. See the NOTICE file distributed with
006 * this work for additional information regarding copyright ownership.
007 * The ASF licenses this file to You under the Apache License, Version 2.0
008 * (the "License"); you may not use this file except in compliance with
009 * the License. You may obtain a copy of the License at
010 *
011 * http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS,
015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016 * See the License for the specific language governing permissions and
017 * limitations under the License.
018 */
019
020 /*
021 * Created 22.10.2003 16:57:20.
022 * $Id: ClearValidatorsActionListener.java 601107 2007-12-04 22:12:14Z bommel $
023 */
024
025 import org.apache.commons.logging.Log;
026 import org.apache.commons.logging.LogFactory;
027 import org.apache.myfaces.tobago.component.ComponentUtil;
028
029 import javax.faces.component.UIComponent;
030 import javax.faces.context.FacesContext;
031 import javax.faces.event.AbortProcessingException;
032 import javax.faces.event.ActionEvent;
033 import javax.faces.event.ActionListener;
034 import javax.faces.event.PhaseId;
035 import java.util.StringTokenizer;
036
037 public class ClearValidatorsActionListener implements ActionListener {
038
039 private static final Log LOG
040 = LogFactory.getLog(ClearValidatorsActionListener.class);
041
042 public PhaseId getPhaseId() {
043 return PhaseId.APPLY_REQUEST_VALUES;
044 }
045
046 public void processAction(ActionEvent actionEvent)
047 throws AbortProcessingException {
048 if (LOG.isDebugEnabled()) {
049 LOG.debug("actionEvent = '" + actionEvent + "'");
050 }
051 UIComponent source = actionEvent.getComponent();
052 String clearValidatorsFieldIds
053 = (String) ComponentUtil.findParameter(source, "clearValidatorsFieldIds");
054
055 if (LOG.isDebugEnabled()) {
056 LOG.debug("clearValidatorsFieldIds = '" + clearValidatorsFieldIds + "'");
057 }
058
059 // FIXME: finding mechanism??? JSF ???
060
061 for (StringTokenizer tokenizer
062 = new StringTokenizer(clearValidatorsFieldIds, ",");
063 tokenizer.hasMoreTokens();) {
064 String clearValidatorsFieldId = tokenizer.nextToken();
065
066 UIComponent component = source.findComponent(clearValidatorsFieldId);
067 if (LOG.isDebugEnabled()) {
068 LOG.debug("component = '" + component + "'");
069 }
070
071 if (component == null) { // not found locally
072 if (LOG.isDebugEnabled()) {
073 LOG.debug("Component not found locally, asking the tree.");
074 }
075 FacesContext facesContext = FacesContext.getCurrentInstance();
076 component = facesContext.getViewRoot().findComponent(clearValidatorsFieldId);
077 }
078
079 if (component == null) { // not found
080 LOG.warn("Component not found.");
081 } else {
082 // component.clearValidators();
083 LOG.error("NO LONGER AVAILABLE: component.clearValidators();");
084 }
085 }
086 }
087
088 }