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 985178 2010-08-13 12:39:35Z lofwyr $ 023 */ 024 025 import org.apache.myfaces.tobago.util.ComponentUtils; 026 import org.slf4j.Logger; 027 import org.slf4j.LoggerFactory; 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 Logger LOG = LoggerFactory.getLogger(ClearValidatorsActionListener.class); 040 041 public PhaseId getPhaseId() { 042 return PhaseId.APPLY_REQUEST_VALUES; 043 } 044 045 public void processAction(ActionEvent actionEvent) throws AbortProcessingException { 046 if (LOG.isDebugEnabled()) { 047 LOG.debug("actionEvent = '" + actionEvent + "'"); 048 } 049 UIComponent source = actionEvent.getComponent(); 050 String clearValidatorsFieldIds 051 = (String) ComponentUtils.findParameter(source, "clearValidatorsFieldIds"); 052 053 if (LOG.isDebugEnabled()) { 054 LOG.debug("clearValidatorsFieldIds = '" + clearValidatorsFieldIds + "'"); 055 } 056 057 // FIXME: finding mechanism??? JSF ??? 058 059 for (StringTokenizer tokenizer 060 = new StringTokenizer(clearValidatorsFieldIds, ","); 061 tokenizer.hasMoreTokens();) { 062 String clearValidatorsFieldId = tokenizer.nextToken(); 063 064 UIComponent component = source.findComponent(clearValidatorsFieldId); 065 if (LOG.isDebugEnabled()) { 066 LOG.debug("component = '" + component + "'"); 067 } 068 069 if (component == null) { // not found locally 070 if (LOG.isDebugEnabled()) { 071 LOG.debug("Component not found locally, asking the tree."); 072 } 073 FacesContext facesContext = FacesContext.getCurrentInstance(); 074 component = facesContext.getViewRoot().findComponent(clearValidatorsFieldId); 075 } 076 077 if (component == null) { // not found 078 LOG.warn("Component not found."); 079 } else { 080 // component.clearValidators(); 081 LOG.error("NO LONGER AVAILABLE: component.clearValidators();"); 082 } 083 } 084 } 085 086 }