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 * Date: Oct 17, 2006 030 * Time: 12:35:01 AM 031 */ 032 033 /** 034 * Register an SubmittedValueLengthValidator instance on the UIComponent 035 * associated with the closest parent UIComponent custom action. 036 */ 037 @Tag(name = "validateSubmittedValueLength") 038 public class SubmittedValueLengthValidatorTag extends ValidatorTag { 039 040 private static final long serialVersionUID = 6777040780038715924L; 041 042 private String minimum; 043 private String maximum; 044 045 public String getMinimum() { 046 return minimum; 047 } 048 049 @TagAttribute() 050 public void setMinimum(String minimum) { 051 this.minimum = minimum; 052 } 053 054 public String getMaximum() { 055 return maximum; 056 } 057 058 @TagAttribute() 059 public void setMaximum(String maximum) { 060 this.maximum = maximum; 061 } 062 063 protected Validator createValidator() throws JspException { 064 setValidatorId(SubmittedValueLengthValidator.VALIDATOR_ID); 065 SubmittedValueLengthValidator validator = (SubmittedValueLengthValidator) super.createValidator(); 066 if (minimum != null) { 067 try { 068 validator.setMinimum(Integer.parseInt(minimum)); 069 } catch (NumberFormatException e) { 070 // ignore 071 } 072 } 073 if (maximum != null) { 074 try { 075 validator.setMaximum(Integer.parseInt(maximum)); 076 } catch (NumberFormatException e) { 077 // ignore 078 } 079 } 080 return validator; 081 } 082 083 084 public void release() { 085 super.release(); 086 minimum = null; 087 maximum = null; 088 } 089 }