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