[ http://issues.apache.org/jira/browse/MYFACES-372?page=all ]
     
sean schofield closed MYFACES-372:
----------------------------------

    Fix Version: Nightly Build
     Resolution: Fixed

> url validator tag based on emailvalidator
> -----------------------------------------
>
>          Key: MYFACES-372
>          URL: http://issues.apache.org/jira/browse/MYFACES-372
>      Project: MyFaces
>         Type: New Feature
>   Components: Sandbox
>     Versions: Nightly Build
>  Environment: windows
>     Reporter: Fabian Frederick
>     Assignee: sean schofield
>     Priority: Trivial
>      Fix For: Nightly Build

>
> Index: tomahawk/tld/myfaces_ext.tld
> ===================================================================
> --- tomahawk/tld/myfaces_ext.tld      (revision 225811)
> +++ tomahawk/tld/myfaces_ext.tld      (working copy)
> @@ -2381,6 +2381,15 @@
>                       A custom validator for email address format, based 
> upons Jakarta Commons.
>          </description>
>       </tag>
> +    <!-- Validator for Url -->
> +     <tag>
> +        <name>validateUrl</name>
> +        
> <tag-class>org.apache.myfaces.custom.emailvalidator.ValidateUrlTag</tag-class>
> +        <body-content>JSP</body-content>
> +        <description>
> +                     A custom validator for url format, based upons Jakarta 
> Commons.
> +        </description>
> +     </tag>
>      <!-- Validator for ISBN -->
>       <!--tag>
> Index: tomahawk/conf/faces-config.xml
> ===================================================================
> --- tomahawk/conf/faces-config.xml    (revision 225811)
> +++ tomahawk/conf/faces-config.xml    (working copy)
> @@ -720,6 +720,11 @@
>       </validator>
>       <validator>
> +             <validator-id>org.apache.myfaces.validator.Url</validator-id>
> +             
> <validator-class>org.apache.myfaces.custom.urlvalidator.UrlValidator</validator-class>
> +     </validator>
> +
> +     <validator>
>               <validator-id>org.apache.myfaces.validator.Equal</validator-id>
>               
> <validator-class>org.apache.myfaces.custom.equalvalidator.EqualValidator</validator-class>
>       </validator>
> Index: 
> tomahawk/src/java/org/apache/myfaces/custom/urlvalidator/UrlValidator.java
> ===================================================================
> --- 
> tomahawk/src/java/org/apache/myfaces/custom/urlvalidator/UrlValidator.java    
>     (revision 0)
> +++ 
> tomahawk/src/java/org/apache/myfaces/custom/urlvalidator/UrlValidator.java    
>     (revision 0)
> @@ -0,0 +1,54 @@
> +package org.apache.myfaces.custom.urlvalidator;
> +
> +import org.apache.myfaces.util.MessageUtils;
> +
> +import org.apache.commons.validator.GenericValidator;
> +
> +import javax.faces.application.FacesMessage;
> +import javax.faces.component.UIComponent;
> +import javax.faces.context.FacesContext;
> +import javax.faces.validator.Validator;
> +import javax.faces.validator.ValidatorException;
> +
> +public class UrlValidator implements Validator {
> +
> +     /**
> +      * <p>The standard converter id for this converter.</p>
> +      */
> +     public static final String      VALIDATOR_ID       = 
> "org.apache.myfaces.validator.Url";
> +     /**
> +      * <p>The message identifier of the [EMAIL PROTECTED] FacesMessage} to 
> be created if
> +      * the maximum length check fails.</p>
> +      */
> +     public static final String URL_MESSAGE_ID = 
> "org.apache.myfaces.Url.INVALID";
> +
> +     public UrlValidator(){
> +     }
> +
> +     /**
> +      * method that validates an url address.
> +      * it uses the commons-validator
> +      */
> +     public void validate(
> +             FacesContext facesContext,
> +             UIComponent uiComponent,
> +             Object value)
> +             throws ValidatorException {
> +
> +
> +                     if (facesContext == null) throw new 
> NullPointerException("facesContext");
> +                     if (uiComponent == null) throw new 
> NullPointerException("uiComponent");
> +
> +                     if (value == null)
> +                     {
> +                             return;
> +                     }
> +                     if (!GenericValidator.isUrl(value.toString())) {
> +                             Object[] args = {value.toString()};
> +                             throw new 
> ValidatorException(MessageUtils.getMessage(FacesMessage.SEVERITY_ERROR,URL_MESSAGE_ID,
>  args));
> +
> +                     }
> +
> +     }
> +
> +}
> Index: 
> tomahawk/src/java/org/apache/myfaces/custom/urlvalidator/ValidateUrlTag.java
> ===================================================================
> --- 
> tomahawk/src/java/org/apache/myfaces/custom/urlvalidator/ValidateUrlTag.java  
>     (revision 0)
> +++ 
> tomahawk/src/java/org/apache/myfaces/custom/urlvalidator/ValidateUrlTag.java  
>     (revision 0)
> @@ -0,0 +1,27 @@
> +package org.apache.myfaces.custom.urlvalidator;
> +
> +import javax.faces.validator.Validator;
> +import javax.faces.webapp.ValidatorTag;
> +import javax.servlet.jsp.JspException;
> +
> +public class ValidateUrlTag extends ValidatorTag
> +{
> +  private static final long serialVersionUID = 6041422002721046221L;
> +
> +  public ValidateUrlTag()
> +    {
> +     }
> +
> +     protected Validator createValidator() throws JspException
> +    {
> +             setValidatorId(UrlValidator.VALIDATOR_ID);
> +         UrlValidator validator = (UrlValidator)super.createValidator();
> +             return validator;
> +     }
> +
> +    public void release()
> +    {
> +        super.release();
> +    }
> +
> +}</textarea>
>                     </td>
>     </tr>
>     
>                     
>                 
>             
>                 
>                 
>                     
>                     
>                         
>                     
>                 
>             
>         
>         
>             
>     <tr><td colspan=2 bgcolor=ffffff>&nbsp;
>     <style>
>     <!--
>     .fieldLabelArea
>     {
>         width: 30%;
>     }
>     -->
>     </style>
>     </td></tr>
>     <tr><td colspan=2 bgcolor=f0f0f0>
>         <b>Comment</b>: (an optional comment describing this update)
>     </td></tr>
>     
>       
>       <tr 
>         
>         
>     >
>               
>               
>                       
>                       
>                               <td class="fieldLabelArea">
>                       
>               
>         
>         
>               
>               Update comment:
>         
>         
>               </td>
>       
>       
>       <td bgcolor="ffffff" nowrap class="fieldValueArea">
> <textarea name="comment"
>           cols="70"
>           rows="4"
>           wrap="virtual"
>             
>             
>             style="width:90%"
>          
>          
>             
>          
>          
>             accesskey="m"
>          
>          
>             
>          
>          
>             
>          
>          
>             
>          
>          
>             
>          
>          
>             
>          
>          
>             
>          
> >

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira

Reply via email to