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    
042      private static final long serialVersionUID = 6777040780038715924L;
043    
044      private String minimum;
045      private String maximum;
046    
047      public String getMinimum() {
048        return minimum;
049      }
050      
051      @TagAttribute()
052      public void setMinimum(String minimum) {
053        this.minimum = minimum;
054      }
055    
056      public String getMaximum() {
057        return maximum;
058      }
059      @TagAttribute()
060      public void setMaximum(String maximum) {
061        this.maximum = maximum;
062      }
063    
064      protected Validator createValidator() throws JspException {
065        setValidatorId(SubmittedValueLengthValidator.VALIDATOR_ID);
066        SubmittedValueLengthValidator validator = (SubmittedValueLengthValidator) super.createValidator();
067        if (minimum != null) {
068          try {
069            validator.setMinimum(Integer.parseInt(minimum));
070          } catch(NumberFormatException e) {
071            // ignore
072          }
073        }
074        if (maximum != null) {
075          try {
076            validator.setMaximum(Integer.parseInt(maximum));
077          } catch(NumberFormatException e) {
078            // ignore
079          }
080        }
081        return validator;
082      }
083    
084    
085      public void release() {
086        super.release();
087        minimum = null;
088        maximum = null;
089      }
090    }