You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by "Martin Grigorov (Resolved) (JIRA)" <ji...@apache.org> on 2012/02/09 14:54:06 UTC

[jira] [Resolved] (WICKET-4379) org.apache.wicket.validation.ValidatorAdapter class causes problem with validator properties to be loaded

     [ https://issues.apache.org/jira/browse/WICKET-4379?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Martin Grigorov resolved WICKET-4379.
-------------------------------------

       Resolution: Fixed
    Fix Version/s: 6.0.0
         Assignee: Martin Grigorov
    
> org.apache.wicket.validation.ValidatorAdapter class causes problem with validator properties to be loaded
> ---------------------------------------------------------------------------------------------------------
>
>                 Key: WICKET-4379
>                 URL: https://issues.apache.org/jira/browse/WICKET-4379
>             Project: Wicket
>          Issue Type: Bug
>          Components: wicket
>    Affects Versions: 1.5.4
>         Environment: Windows 7, Netbeans 7.0.1, Java 6 SE (HotSpot)
>            Reporter: MichaƂ Bartoszewski
>            Assignee: Martin Grigorov
>            Priority: Minor
>             Fix For: 1.5.5, 6.0.0
>
>
> PROBLEM:
> <e1nPL> hi I am having such problem: 
> <e1nPL> I have implemented validator by implementing IValidator<T> interface
> <e1nPL> and I have impelemnted the same validator by extending AbstractValidator<T> class
> CODE:
>     ===================== VALIDATOR EXTENDED FROM AbstractValidator =====================
>     package com.mycompany;
>      
>     import java.util.regex.Pattern;
>     import org.apache.wicket.IClusterable;
>     import org.apache.wicket.util.lang.Classes;
>     import org.apache.wicket.validation.IValidatable;
>     import org.apache.wicket.validation.IValidator;
>     import org.apache.wicket.validation.ValidationError;
>     import org.apache.wicket.validation.validator.AbstractValidator;
>      
>     /**
>      *
>      * @author e1n
>      */
>     public class PasswordPolicyValidator<T> extends AbstractValidator<T> {
>      
>         private static final Pattern UPPER = Pattern.compile("[A-Z]");
>         private static final Pattern LOWER = Pattern.compile("[a-z]");
>         private static final Pattern NUMBER = Pattern.compile("[0-9]");
>        
>         @Override
>         public void onValidate(IValidatable<T> validatable) {
>             final String password = (String)validatable.getValue();
>            
>             if (!NUMBER.matcher(password).find()) {
>                 error(validatable, "no-digit");
>             }
>             if (!LOWER.matcher(password).find()) {
>                 error(validatable, "no-lower");
>             }
>             if (!UPPER.matcher(password).find()) {
>                 error(validatable, "no-upper");
>             }
>      
>         }
>        
>         @Override
>         public void error(IValidatable<T> validatable, String errorKey) {
>             ValidationError err = new ValidationError();
>             err.addMessageKey(Classes.simpleName(getClass()) + "." + errorKey);
>             validatable.error(err);
>         }
>        
>     }
>      
>      
>     =============== VALIDATOR directly implementing IValidator interfce ====================
>     package com.mycompany;
>      
>     import java.util.regex.Pattern;
>     import org.apache.wicket.IClusterable;
>     import org.apache.wicket.util.lang.Classes;
>     import org.apache.wicket.validation.IValidatable;
>     import org.apache.wicket.validation.IValidator;
>     import org.apache.wicket.validation.ValidationError;
>     import org.apache.wicket.validation.validator.AbstractValidator;
>      
>     /**
>      *
>      * @author e1n
>      */
>     public class PasswordPolicyValidator<T> implements IValidator<T> {
>      
>         private static final Pattern UPPER = Pattern.compile("[A-Z]");
>         private static final Pattern LOWER = Pattern.compile("[a-z]");
>         private static final Pattern NUMBER = Pattern.compile("[0-9]");
>      
>         public void validate(IValidatable<T> validatable) {
>             final String password = (String)validatable.getValue();
>            
>             if (!NUMBER.matcher(password).find()) {
>                 error(validatable, "no-digit");
>             }
>             if (!LOWER.matcher(password).find()) {
>                 error(validatable, "no-lower");
>             }
>             if (!UPPER.matcher(password).find()) {
>                 error(validatable, "no-upper");
>             }
>      
>         }
>        
>         public void error(IValidatable<T> validatable, String errorKey) {
>             ValidationError err = new ValidationError();
>             err.addMessageKey(Classes.simpleName(getClass()) + "." + errorKey);
>             validatable.error(err);
>         }
>        
>     }
> <e1nPL> I also have properties file which is named after validator class
> <e1nPL> and placed in the same package
> <e1nPL> my problem is that when i use to validate my form field validator which implements IValidator interface it is not capable of loading error messages from properties file
> <e1nPL> but when i am using validator which is extending AbstractValidator class
> <e1nPL> properties file with error msgs gets loaded
> POSSIBLE FIX:
> <e1nPL> ok i have found class which is responsible for my problem and it is probably a bug
> <e1nPL> org.apache.wicket.validation.ValidatorAdapter
> <e1nPL> which wraps classes that directly implements IValidator interface
> <e1nPL> then when resources are loaded, and properties file are searched in class path etc., loaders search in wrong path that is build against org.apache.wicket.validation.ValidatorAdapter 
> PLACE WHER FIX SHOULD OCCOUR
> org.apache.wicket.resource.loader.ValidatorStringResourceLoader::loadStringResource(java.lang.Class,java.lang.String,java.util.Locale,java.lang.String,java.lang.String)

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira