001    package org.apache.myfaces.tobago.taglib.component;
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    import org.apache.myfaces.tobago.validator.SubmittedValueLengthValidator;
021    import org.apache.myfaces.tobago.apt.annotation.Tag;
022    import org.apache.myfaces.tobago.apt.annotation.TagAttribute;
023    
024    import javax.faces.webapp.ValidatorTag;
025    import javax.faces.validator.Validator;
026    import javax.servlet.jsp.JspException;
027    
028    /*
029     * Created by IntelliJ IDEA.
030     * User: bommel
031     * Date: Oct 17, 2006
032     * Time: 12:35:01 AM
033     */
034    
035    /**
036     * Register an SubmittedValueLengthValidator instance on the UIComponent
037     * associated with the closest parent UIComponent custom action.
038     */
039    @Tag(name="validateSubmittedValueLength")
040    public class SubmittedValueLengthValidatorTag extends ValidatorTag {
041      private String minimum;
042      private String maximum;
043    
044    
045      public String getMinimum() {
046        return minimum;
047      }
048      @TagAttribute()
049      public void setMinimum(String minimum) {
050        this.minimum = minimum;
051      }
052    
053      public String getMaximum() {
054        return maximum;
055      }
056      @TagAttribute()
057      public void setMaximum(String maximum) {
058        this.maximum = maximum;
059      }
060    
061      protected Validator createValidator() throws JspException {
062        setValidatorId(SubmittedValueLengthValidator.VALIDATOR_ID);
063        SubmittedValueLengthValidator validator = (SubmittedValueLengthValidator) super.createValidator();
064        if (minimum != null) {
065          try {
066            validator.setMinimum(Integer.parseInt(minimum));
067          } catch(NumberFormatException e) {
068            // ignore
069          }
070        }
071        if (maximum != null) {
072          try {
073            validator.setMaximum(Integer.parseInt(maximum));
074          } catch(NumberFormatException e) {
075            // ignore
076          }
077        }
078        return validator;
079      }
080    
081    
082      public void release() {
083        super.release();
084        minimum = null;
085        maximum = null;
086      }
087    }