Adam, I forwarded one of my replies by mistake to the developer list, but one of the committers picked up on it so I thought I'd let you know if you'd like to get into the dicussion over there
Niall ----- Original Message ----- From: "Adam Hardy" <[EMAIL PROTECTED]> To: "Struts Users Mailing List" <[EMAIL PROTECTED]> Sent: Thursday, April 01, 2004 3:24 PM Subject: Re: UrlValidator() takes options - but how? > Thanks for that Niall, you certainly know your stuff. > > I am thinking, if I change the UrlValidator in the source code, I could > submit a patch to allow FieldChecks to set the <var> values from > validation.xml. > > Currently, FieldChecks access UrlValidator via the GenericValidator: > > if (!GenericValidator.isBlankOrNull(value) && > !GenericValidator.isUrl(value)) { > > Should I change this to: > > !GenericValidator.isUrl(value, allow2Slashes, noFragments, > allowAllSchems)) { > > and edit GenericValidator accordingly, to pass the options in to > UrlValidator. > > Is that a good idea? > Adam > > > On 04/01/2004 02:58 PM Niall Pemberton wrote: > > UrlValidator is not the class that is instantiated by ValidatorAction > > because it doesn't know anything about Struts resources - the Struts > > FieldChecks.validateUrl() method calls commons GenericValidator which > > instantiates the UrlValidator. > > > > Rather than using the struts FieldChecks.validateUrl(), create you own > > version which instantiates the url validator and picks up <var> values to > > configure it. Something like: > > > > > > <field property="someUrl" depends="myUrlValidator"> > > <var><var-name>slashes</var-name> > > <var-value>true</var-value> > > </var> > > <var><var-name>fragments</var-name> > > <var-value>true</var-value> > > </var> > > </field> > > > > public static boolean validateUrl(Object bean, > > ValidatorAction va, Field field, > > ActionMessages errors, > > HttpServletRequest request) { > > > > String value = null; > > if (isString(bean)) { > > value = (String) bean; > > } else { > > value = ValidatorUtils.getValueAsString(bean, > > field.getProperty()); > > } > > int options = 0; > > > > if ("true".equals(field.getVarValue("slashes"))) > > options += UrlValidator.ALLOW_2_SLASHES; > > > > if ("true".equals(field.getVarValue("fragments"))) > > options += UrlValidator.ALLOW_2_SLASHES; > > > > UrlValidator urlValidator = new UrlValidator(options); > > > > if (!GenericValidator.isBlankOrNull(value) && > > !urlValidator.isValid(value)) { > > errors.add(field.getKey(), Resources.getActionMessage(request, > > va, field)); > > return false; > > } else { > > return true; > > } > > } > > > > ----- Original Message ----- > > From: "Adam Hardy" <[EMAIL PROTECTED]> > > To: <[EMAIL PROTECTED]> > > Sent: Thursday, April 01, 2004 12:17 PM > > Subject: UrlValidator() takes options - but how? > > > > > > > >>In UrlValidator() in the validator package, one can set various options > >>upon instantiation, such as ALLOW_2_SLASHES or NO_FRAGMENTS. > >> > >>However it appears from the code in > >>ValidatorAction.getValidationClassInstance() that I can't actually set > >>these at any point in the Validator framework so that they will be > >>picked up when run under struts. > >> > >>I think I'm looking in the right place in the code. > >> > >>I was hoping that there would be some method for configuring this via > >>validation.xml, but apparently not. > >> > >>Am I correct? > >> > >>Thanks > >>Adam > >> > >>-- > >>struts 1.1 + tomcat 5.0.16 + java 1.4.2 > >>Linux 2.4.20 Debian > >> > >> > >>--------------------------------------------------------------------- > >>To unsubscribe, e-mail: [EMAIL PROTECTED] > >>For additional commands, e-mail: [EMAIL PROTECTED] > >> > >> > >> > > > > > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > > -- > struts 1.2 + tomcat 5.0.19 + java 1.4.2 > Linux 2.4.20 Debian > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]