[ http://issues.apache.org/jira/browse/MYFACES-372?page=comments#action_12317134 ]
sean schofield commented on MYFACES-372: ---------------------------------------- Fabian, thanks for contributing. Can you do me a favor and generate a new patch after moving the component to sandbox? All of our new widgets go in the sandbox before they are voted into tomahawk. Also, please create the patch as an attachment (instead of pasting into JIRA.) Thanks again for your contribution. > url validator tag / tomahawk based on emailvalidator > ---------------------------------------------------- > > Key: MYFACES-372 > URL: http://issues.apache.org/jira/browse/MYFACES-372 > Project: MyFaces > Type: New Feature > Versions: Nightly Build > Environment: windows > Reporter: Fabian Frederick > Priority: Trivial > > 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(); > + } > + > +} -- 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
